# Rsync [Rsync](/https://rsync.samba.org/) is a very useful tool for backing up files. It can be used remotely. **WARNING**: If your filesystem is being actively written to, data corruption may occur. ## Rsync Primer OpenBSD includes its own rewrite of rsync called [openrsync](/https://man.openbsd.org/openrsync). It seems to be a bit buggy so I am going to use rsync instead. The commands below, however, will work with either openrsync or rsync. Here's how to back up the file /path/to/file on ircnow.org with username to the current directory: $ rsync -a username@ircnow.org:/path/to/file ./ We add the option `-a` for archive mode. If you have multiple files, you can use the shorthand of :/path/to/second/file: $ rsync -a username@ircnow.org:/path/to/file :/path/to/second/file ./ This copies both /path/to/file and /path/to/second/file from ircnow.org to your current local directory. $ rsync -a username@ircnow.org:/path/to/file :/path/to/second/file ./ We add `-v` options to turn on verbosity (it will display each file copied). $ rsync -v username@ircnow.org:/path/to/file ./ ## Quick Check Before you backup your files, make sure you have enough disk space. To see how much space it will take, and how much you have available, run: $ df -h Filesystem Size Used Avail Capacity Mounted on /dev/sd0a 1005M 111M 844M 12%25 / /dev/sd0k 192G 28.7G 153G 16%25 /home /dev/sd0d 3.9G 22.1M 3.7G 1%25 /tmp /dev/sd0f 12.3G 7.3G 4.4G 63%25 /usr /dev/sd0e 14.7G 41.2M 14.0G 0%25 /var Backing up /home will require at least 28.7G of space. $ rsync --rsync-path="doas rsync" -avz username@example.com:/home/username /dest/path/ This will copy everything in /home/username on example.com into /dest/path/. `-a` specifies this is an archive, `-v` tells rsync to be more verbose (show files), and `z` tells rsync to compress during the transfer.. (:if false:) ## Complete Functions Put the following functions at the end of ~/.profile: rsync-all () { echo "Backing up in $PWD: type ctrl+c to abort, enter to continue" read $cancel ssh $1 "doas dump -0 -a -u -h 0 -f - /" > root.dmp ssh $1 "doas dump -0 -a -u -h 0 -f - /home" > home.dmp ssh $1 "doas dump -0 -a -u -h 0 -f - /home/vmm" > vmm.dmp ssh $1 "doas dump -0 -a -u -h 0 -f - /mnt" > mnt.dmp ssh $1 "doas dump -0 -a -u -h 0 -f - /var" > var.dmp ssh $1 "doas dump -0 -a -u -h 0 -f - /var/www/htdocs" > htdocs.dmp ssh $1 "doas dump -0 -a -u -h 0 -f - /usr" > usr.dmp date > date md5 root.dmp home.dmp vmm.dmp mnt.dmp var.dmp htdocs.dmp usr.dmp date > md5sum } `rsync-all` will make a complete backup of the remote system you specify. Source it, then call it on the server: $ . .profile $ rsync-all example.ircnow.org (:ifend:)