I am mainly a developer and use server just to get my code online so I often forget how to use rsync. So here is my cheat sheet for rsync 🙂
- -v : verbose
- -r : copies data recursively (but don’t preserve timestamps and permission while transferring data
- -a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
- -z : compress file data
- -h : human-readable, output numbers in a human-readable format
Do a Dry Run with rsync
Use of this option (–dry-run) will not make any changes only do a dry run of the command and shows the output of the command, if the output shows exactly same you want to do then you can remove ‘–dry-run‘ option from your command and run on the terminal.
rsync --dry-run --remove-source-files -zvh backup.tar /tmp/backups/
Copy/Sync a Directory on Local computer
rsync -avzh /root/rpmpkgs /tmp/backups/
Copy a File from a Remote Server to a Local Server with SSH
rsync -avzhe ssh root@192.168.0.100:/root/install.log /home/destination
Exclude multiple files and directories at the same time
rsync -avzh --exclude file1.txt --exclude dir3/file4.txt SOURCE/ DESTINATION/