unix

How do I run a local rsync backup to copy data on my Linux server?

Using rsync to keep a local copy or migrate data is very useful because it picks up where it left off if you ever had to kill it or it aborted.

1. When you use rsync, it’s always a good idea to test it with a “–dry-run” first to see what will be copied/updated.

# cd /; rsync –dry-run -a -v /var/www/html /backups

This will output onto the screen what actually would be copied.

2. If the output looks good, you can run it without the –dry-run option. If it’s a large copy that will take more than a few seconds or minutes, it’s always good to run it with nohup so you ensure the job runs to completion.

# cd /; nohup rsync -a -v /var/www/html /backups > /tmp/html_rsync.out 2>&1&

3. When you’re done, you can review the file /tmp/html_rsync.out to see what was transferred.

4. If this is something you want to do on a regular basis, you can schedule a cron job.

Ex. # crontab -e
0 22 * * * /usr/local/bin/html_rsync.sh

5. Another option to keep in mind if you want to keep the directories completely in sync is the –delete flag. It will delete files on the destination.

# cd /; nohup rsync -a -v –delete /var/www/html /backups > /tmp/html_rsync.out 2>&1&

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top