Rsync Tricks

November 3, 2013   

scp and rsync are the two popular commands for copying files between devices. You can use it for copy, synchronize or backups.

scp

scp is good to use but if the connection between a server and a client disconnect in the middle you have to start copying over again. It doesn’t synchronize
This is the command for using scp

scp -r src/location server:destination/location

rsync

rsync is very power full software For copying, synchronizing and backups files by commands line.

Advantages

  • Copy files to other device.
  • Synchronization.
  • Encryption while transferring files.

Checkout this wonderful article Linux rsync command with practical examples

Syntax:

rsync -options source destination

Basic usage:

rsync -azv src/location username@server:destination/location

Options: –progress: View progress while synchronization
–delete: Delete on destination if not in source
-e ssh: Over SSH

Tricks: Non-interactive password authentication with SSH:

sshpass -p 'password' rsync -avz --progress sshpass.tar.gz root@ldap.nextstep4it.com:/tmp/

Include and exclude options

rsync -avz --include 'P*' --exclude '*' user@server:src/location  /dest/location

Use rsync with cron job to automatically backup your files.

$ contab -e

To backups every 1 hour, type this line. Check cron configuration for more details

0 * * * * /usr/bin/rsync --delete -azv src/location username@server:destination/location > /dev/null

Optional: You could first make a comprised file with a date before backup

0 * * * * cd src/location ; /bin/tar -czvf name_of_comprised_file-`/bin/date +%a`.tar.gz src/folder > /dev/null

Reference:



comments powered by Disqus