Tuesday | 05 NOV 2024
[ previous ]
[ next ]

Rsync Cheatsheet

Title:
Date: 2022-08-27
Tags:  cheatsheet

A simple example:

sshpass -p "PASSWORD" rsync /home/notes/note1.txt username@website:~/folder/

I switched out the tar, scp and untar script I wrote to deploy my blog for the rsync command. My script was taking just a few seconds too long for me to be happy with it.

I'm still not happy as I also have a git add, commit and push step which is still slow but I'll fix that at some other point.

This is the command to move files from a host machine to a remote machine.

$ rsync -avzcL \
    --delete \
    --exclude='.git/' \
    -e 'ssh -p 23221 -o "IdentitiesOnly=yes" -i ~/.ssh/id_rsa' \
    /usr/share/nginx/html/nivethan/ username@DEST.IP:~/bp/nivethan/
rsync -flags sync_this to_this

The flags are as follows:

-a  Archive, this will preserve the file attributes such as permissions
-v  Verbose, this will display what files are being transfered
-z  Compress, this will compress the data
-c  Checksum, this will push files with differing checksums
-u  Update, this will push files with newer update times than the remote machine


--delete    This will delete files that don't exist on the host machine
--exclude   Exclude specific directories or files from being pushed
--remove-source-files   Delete the files on the source system

-e  Shell program to use, in this case I use ssh but with specific options, by default rsync will use ssh

Use a trailing slash at the end to get errors when the target directory doesn't exist.