RSync Command for Home Directory Backup on Ubuntu/Linux

Mostly for my own reference – this is the command I use to back my home directory on my desktop. Both locations are local, so there is no copying over SSH for this first one.

rsync -rougv --archive --delete-excluded --ignore-errors --exclude=*.gvfs* /home/andrew /backup/

Below is the command that I use for each user on my main file server. This copies over SSH, so I have SSH keys on the destination server so I can run this in a cron job, and it won’t get hung up with a password prompt.

rsync -rougv --archive --delete-excluded --ignore-errors --exclude=*.gvfs* /home/user1 bckup@server-02:/media/external/backups/server-01/

From the man page, here is an explanation on all the options I use:

  • -r, –recursive             recurse into directories
  • -o, –owner                 preserve owner (super-user only)
  • -u, –update                skip files that are newer on the receiver
  • -g, –group                 preserve group
  • -v, –verbose               increase verbosity
  • -a, –archive               archive mode; equals -rlptgoD (no -H,-A,-X)
  • –delete-excluded       also delete excluded files from dest dirs
  • –ignore-errors         delete even if there are I/O errors
  • –exclude=PATTERN       exclude files matching PATTERN (so it doesn’t copy any SSHFS-mounted directories on my system)

Tags:

This entry was posted on Sunday, May 2nd, 2010 at 6:01 pm and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “RSync Command for Home Directory Backup on Ubuntu/Linux”

Torsten Radtke August 7th, 2010 at 3:37 pm

For what it’s worth, here’s my shell script for backing up my server. Local copy from several partition to one fat backup drive. Maybe this could be helpful to someone.
#!/bin/bash

mpbackup=”/backup”
backupdev=”/dev/sdd1″
backupdrv=”/dev/sdd”

/bin/mountpoint $mpbackup
if [ $? -ne 0 ] ; then
echo Disk $backupdev not mounted at mountpoint $mpbackup.
echo Trying to mount it now…
/bin/mount $backupdev $mpbackup
fi

/bin/mountpoint $mpbackup
if [ $? -eq 0 ] ; then
echo `date`: Start Backup /usr/daten*.
echo `date`: Start Backup /usr/daten*. > /var/log/backup.log
rsync -a -v –delete /usr/daten $mpbackup >> /var/log/backup.log
rsync -a -v –delete /usr/daten2 $mpbackup >> /var/log/backup.log
rsync -a -v –delete /usr/daten3 $mpbackup >> /var/log/backup.log
# comment/uncomment previous/next 3 lines for dry run (simulation)
#rsync -n -a -v –delete /usr/daten $mpbackup
#rsync -n -a -v –delete /usr/daten2 $mpbackup
#rsync -n -a -v –delete /usr/daten3 $mpbackup

echo `date`: Start image backup of OS partitions.
echo `date`: Start image backup of OS partitions. >> /var/log/backup.log
dd if=/dev/sda1 of=$mpbackup/sda1-boot.img
#dd if=/dev/sda2 of=$mpbackup/sda2-root.img

cp /backup.sh $mpbackup
df -h | grep -i $backupdev >> /var/log/backup.log
echo `date`: Backup has been finished.
echo `date`: Backup has been finished. >> /var/log/backup.log

echo Unmounting/Stopping disk…
echo Unmounting/Stopping disk… >> /var/log/backup.log
/bin/umount $mpbackup
/usr/bin/sg_start –stop -v $backupdrv
else
echo Disk $backupdev not mounted at mountpoint $mpbackup.
echo *** BACKUP ABORTED ***
fi

Leave a Reply