<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged rsync</title>
<link>https://coderlegion.com/tag/rsync</link>
<description>Powered by Question2Answer</description>
<item>
<title>rsync's dangerous flags don't fail. They do a different job and exit 0.</title>
<link>https://coderlegion.com/28025/rsyncs-dangerous-flags-dont-fail-they-do-a-different-job-and-exit-0</link>
<description>&lt;p&gt;The trap with rsync is that its dangerous flag combinations don't fail — they complete a different operation than the one you intended, and exit 0. &lt;code&gt;--delete&lt;/code&gt; makes the destination match the source, so a mistyped or freshly moved source directory means rsync removes everything at the destination and reports success. Your cron log shows a clean run while the backup empties itself. A trailing slash changes the meaning too: &lt;code&gt;/data/&lt;/code&gt; syncs the directory's contents, while &lt;code&gt;/data&lt;/code&gt; copies the directory itself into the destination — and on a mirror job, that difference decides what gets compared and what gets deleted.&lt;/p&gt;
&lt;p&gt;The defense is previewing every destructive sync before running it live:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;rsync -av --delete --dry-run /srv/www/ user@backup:/srv/backup/www/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Read the &lt;code&gt;deleting …&lt;/code&gt; lines it prints; only when that list matches your expectations do you remove &lt;code&gt;--dry-run&lt;/code&gt;. Note also that excludes take one pattern per flag — &lt;code&gt;--exclude='*.log' --exclude='.git'&lt;/code&gt; — because a comma-separated list inside a single flag silently matches nothing.&lt;/p&gt;
&lt;p&gt;If you'd rather compose the command with those guardrails enforced — a red warning when &lt;code&gt;--delete&lt;/code&gt; is enabled without a dry run, per-pattern quoted excludes, and a live preview of the finished command — I built a &lt;a rel=&quot;nofollow&quot; href=&quot;https://bashsnippets.xyz/tools/rsync-command-builder&quot;&gt;visual rsync command builder with delete-flag guardrails&lt;/a&gt; that runs entirely in the browser.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28025/rsyncs-dangerous-flags-dont-fail-they-do-a-different-job-and-exit-0</guid>
<pubDate>Tue, 20 Oct 2026 13:00:00 +0000</pubDate>
</item>
<item>
<title>Simple backups using Rsync with SSH</title>
<link>https://coderlegion.com/11514/simple-backups-using-rsync-with-ssh</link>
<description>&lt;p&gt;This post explains how to SSH with Rsync to make backup of your system efficiently and securely.&lt;/p&gt;
&lt;p&gt;The only requisite to start here is an access to SSH somewhere.&lt;/p&gt;
&lt;h3 id=&quot;create-your-ssh-keys&quot;&gt;Create your ssh keys&lt;/h3&gt;
&lt;p&gt;Here, i just create a keypair called “rsync”, ssh will create a private and a public key.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ssh-keygen -t ed25519 -o -a 100 -f ~/.ssh/rsync
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After, just send the public key to the server with scp targeting your server.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; scp ~/.ssh/rsync.pub backup@SERVER
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;create-a-backup-script&quot;&gt;Create a backup script&lt;/h3&gt;
&lt;p&gt;Create a shell script named rsync-backup.sh with the following content:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#/usr/bin/env sh

set -o errexit

# All variables
SERVER=&quot;192.168.1.11&quot;
BACKUP_FILE=&quot;/tmp/backup.filter&quot;

# More efficient than playing with --include,--exclude
cat &amp;lt;&amp;lt; EOF &amp;gt; &quot;$BACKUP_FILE&quot;
# Include patterns
+ /documents/***
+ /Downloads/***
+ /downloads/***
+ /images/***
+ /musics/***

# Exclude everything else
- /**
EOF

# And finally the rsync command
rsync -avP --delete -e &quot;ssh -i $HOME/.ssh/rsync&quot; \
    --bwlimit=400 \
    --filter=&quot;merge $BACKUP_FILE&quot; \
    &quot;$HOME/&quot; &quot;backup@${SERVER}:backups/&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The script here will backup your $HOME with only certain directory in the “include pattern list”. Just ensure the server address is correct.&lt;/p&gt;
&lt;p&gt;I also limit the bandwidth because it break my wifi card (bad hardware…)&lt;/p&gt;
&lt;h3 id=&quot;execute-the-script&quot;&gt;Execute the script&lt;/h3&gt;
&lt;p&gt;Just give permission and launch the script.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; chmod u+x rsync-backup.sh
./rsync-backup.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Using SSH with Rsync is an efficient and secure method for backing up your system. By generating SSH keys and creating a simple shell script, you can automate the backup process, ensuring that your important files are safely stored on a remote server.&lt;/p&gt;
&lt;p&gt;Adjusting settings like bandwidth limitation can help optimize performance, especially on networks with limited resources. This approach not only provides a reliable backup solution but also enhances data security through encrypted connections.&lt;/p&gt;
</description>
<category>Tutorials</category>
<guid isPermaLink="true">https://coderlegion.com/11514/simple-backups-using-rsync-with-ssh</guid>
<pubDate>Thu, 12 Feb 2026 13:35:25 +0000</pubDate>
</item>
</channel>
</rss>