rsync is a command-line tool used to copy/clone files (“fast incremental file transfer“). It is a great, simple backup tool. The basic rsync command is this:
rsync -a src dest_dir
Where src is the original directory or file and dest_dir is the destination directory. Because rsync does incremental backups it only adds the file to the dest if it has been updated from the original backup.
rsync -axS src dest_dir
This is the command I use. This command can be used to backup just about anything! The options:
-ameans archive mode which basically means to preserve the file “as is” (same permissions…)-xmeans not to cross file systems boundaries-Smeans to handle sparse files efficiently-voption (verbose) can be used to print whatrsyncis doing
An important note about rsync: when src is a directory a trailing slash (/) tells rsync to copy the “contents” of the directory:
rsync -axS src_dir/ dest_dir ls -1 dest_dir/ file1 file2
Without a trailing slash:
rsync -axS src_dir dest_dir ls -1 dest_dir src_dir
rsync can also use file-lists containing paths of directories and files, to both include and exclude them for backup:
sudo rsync -axS --files-from="incl_file.txt" --exclude-from="excl_file.txt" src_dir dst_dir
src_dir will have to be specified and will have to be relative to paths in the file list:
cat incl_file.txt Desktop/ rsync -axS --files-from="incl_file.txt" --exclude-from="excl_file.txt" /home/user/ dst_dir
rsync can also remove files from the dest_dir with the --delete option, so files that get added to the exclude file or taken out of the include file will removed from dest_dir.
rsync -axS --delete-excluded --files-from="incl_file.txt" --exclude-from="excl_file.txt" /home/user/ dst_dir
Backup Script
I use rsync to backup my system configurations and /home/ to make reinstalling easy. I created the script to remember the command to use, but to also easily add to the include and exclude files:
bcksysc i /etc/hostname Added "/etc/hostname" to bcksysc-inc.txt include file.
Syntax:
bcksysc bcksysc - backup configurations i - add to the include list a file or folder e - add to the exclude list a file or folder c - create backup
Here’s the script all that needs to be done is to change the Parent Destination Directory (for backing up /home/ I copied the script to bckhome, changed the type to home and added /home/ to the include file):
So my destination directory looks like this:
ls -1 /run/media/todd/Backup/rsync/ ... aspire_2012-08-31_sysc aspire_2012-08-31_home
Duplicity is just as easy to use, but provides incremental backups and encryption as well. It will also plug into stuff like Amazon S3 if you want it to: https://grepular.com/Secure_Free_Incremental_and_Instant_Backups_for_Linux
[...] http://linuxtidbits.wordpress.com/2012/08/31/the-beauty-of-rsync-and-backup-script/ Very interesting way to do backups, without install additional sofware [...]