User Tools

Site Tools


computing:rsyncrsnapshot

This is an old revision of the document!



  • rsyncrsnapshot
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

sudo rsync -avxHAX --progress --delete /sourcefiles/path /backup/path

Adding h, H, P, will preserve hard links, give you human readable output, and show the progress (eliminating the need for –progress).

sudo rsync -avxHAXhHP --delete /sourcefiles/path /backup/path

Cloning entire drives, use:

sudo rsync -avxHAXhHP --delete /sourcefiles/path /backup/path --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}

If the drive you are cloning from has a different filesystem than the destination drive, you can remove the exclusions as -x will handle those exclusions in that case. After cloning, you will need to adjust fstab on the destination partition:

cd /etc/
sudo nano fstab
<Edit the drive UUID of the new destination drive>

Now, make the destination volume bootable:

grub-install /dev/sdX

If you are using this method to clone your existing server to another hard drive on the same host, then make sure to run grub-update on the primary OS. After you do that, both the kernels for the primary OS and the cloned OS will appear in GRUB, and you can boot into the clone, specifically, to make sure that everything migrated properly and is in working order. It is not sufficient to simply run rsync and hope that all went well.

rsync over ssh

sudo rsync -avHe --delete -e 'ssh -p 53213' user@172.39.58.38:/home/Archives/ .
sudo rsync -avWeqr --delete -e 'ssh -p 59999' /home/source/ user@10.18.18.2:/media/sdb1/back/

That last one works perfectly … but no matter what, I was having it prompt me for a password despite normal ssh working fine without one.

[Update]

Here is how I got rsync over pub key authentication (no password prompt) working properly on Debian 9.7. This is an answer on Stack Exchange:

The examples provided as answers here either provide an alternate solutions or make the official solution unclear. Here are two examples with explicit path examples and entries so people can adjust for their needs without interpreting obtuse bash notation:

Execute this from the target backup machine, which pulls from source to target backup

rsync -avWeqr --delete -e 'ssh -p 59333 -i /home/user/.ssh/id_rsa' user@10.1.999.3:/home/user/Server/ /home/user/Server/

Execute this from the source machine, which sends from source to target backup

rsync -avWeqr --delete -e 'ssh -p 59333 -i /home/user/.ssh/id_rsa' /home/user/Server/ user@10.1.999.3:/home/user/Server/

Since ssh public key authentication is a requirement for this question's answer, the solution is in telling rsync where to locate the private key, that matches an authorized public key on the destination server. You can create specific ssh keys on each end if you are a security freak, or even distinct keys just for the rsync use that differ from your user. But this is a bit complicated and not needed if these hosts are behind a firewall on a secure LAN. In that case, I recommend using the same ssh public/private keypair on both machines.

Also, I might add that the initial rsync flags, are to an extent, optional, but the specific arrangement `-avWeqr`, was needed for me in order to get `–delete` working properly with all the other parameters. These were tested on Debian 9.7 and work.

This tutorial is a designated “Invariant Section” of the “Technotronic” section of Haack's Wiki as described on the Start Page.

oemb1905 2019/04/09 19:26

computing/rsyncrsnapshot.1554868997.txt.gz · Last modified: 2019/04/10 04:03 by oemb1905