version=pmwiki-2.2.130 ordered=1 urlencoded=1 agent=w3m/0.5.3+git20210102 author=jrmu charset=UTF-8 csum= ctime=1626616894 host=38.87.162.8 name=Rsync.Usage rev=4 targets= text=(:title Rsync:)%0a%0a[[https://rsync.samba.org/|Rsync]] is a very useful tool for backing up files. It can be used remotely.%0a%0a'''WARNING''': If your filesystem is being actively written to, data corruption may occur.%0a%0a!! Rsync Primer%0a%0aOpenBSD includes its own rewrite of rsync called [[https://man.openbsd.org/openrsync|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.%0a%0aHere's how to back up the file /path/to/file on ircnow.org with username to the current directory:%0a%0a[@%0a$ rsync -a username@ircnow.org:/path/to/file ./%0a@]%0a%0aWe add the option @@-a@@ for archive mode.%0a%0aIf you have multiple files, you can use the shorthand of :/path/to/second/file:%0a%0a[@%0a$ rsync -a username@ircnow.org:/path/to/file :/path/to/second/file ./%0a@]%0a%0aThis copies both /path/to/file and /path/to/second/file from ircnow.org to your current local directory.%0a%0a[@%0a$ rsync -a username@ircnow.org:/path/to/file :/path/to/second/file ./%0a@]%0a%0aWe add @@-v@@ options to turn on verbosity (it will display each file copied).%0a%0a[@%0a$ rsync -v username@ircnow.org:/path/to/file ./%0a@]%0a%0a%0a!! Quick Check%0a%0aBefore 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:%0a%0a[@%0a$ df -h%0aFilesystem Size Used Avail Capacity Mounted on%0a/dev/sd0a 1005M 111M 844M 12%25 /%0a/dev/sd0k 192G 28.7G 153G 16%25 /home%0a/dev/sd0d 3.9G 22.1M 3.7G 1%25 /tmp%0a/dev/sd0f 12.3G 7.3G 4.4G 63%25 /usr%0a/dev/sd0e 14.7G 41.2M 14.0G 0%25 /var%0a@]%0a%0aBacking up /home will require at least 28.7G of space.%0a%0a%0a[@%0a$ rsync --rsync-path="doas rsync" -avz username@example.com:/home/username /dest/path/%0a@]%0a%0aThis 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..%0a%0a(:if false:)%0a!! Complete Functions%0a%0aPut the following functions at the end of ~/.profile:%0a%0a[@%0arsync-all () {%0a echo "Backing up in $PWD: type ctrl+c to abort, enter to continue"%0a read $cancel%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /" > root.dmp%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /home" > home.dmp%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /home/vmm" > vmm.dmp%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /mnt" > mnt.dmp%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /var" > var.dmp%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /var/www/htdocs" > htdocs.dmp%0a ssh $1 "doas dump -0 -a -u -h 0 -f - /usr" > usr.dmp%0a date > date%0a md5 root.dmp home.dmp vmm.dmp mnt.dmp var.dmp htdocs.dmp usr.dmp date > md5sum%0a}%0a%0a@@rsync-all@@ will make a complete backup of the remote system you specify.%0a%0aSource it, then call it on the server:%0a%0a[@%0a$ . .profile%0a$ rsync-all example.ircnow.org%0a@]%0a(:ifend:)%0a time=1626661855 title=Rsync author:1626661855=jrmu diff:1626661855:1626661826:=61c61%0a%3c (:if false:)%0a---%0a> (:if false)%0a host:1626661855=38.87.162.8 author:1626661826=jrmu diff:1626661826:1626617401:=61d60%0a%3c (:if false)%0a89d87%0a%3c (:ifend:)%0a host:1626661826=38.87.162.8 author:1626617401=jrmu diff:1626617401:1626616894:=34c34%0a%3c $ rsync -v username@ircnow.org:/path/to/file ./%0a---%0a> $ rsync username@ircnow.org:/path/to/file ./%0a56c56%0a%3c $ rsync --rsync-path="doas rsync" -avz username@example.com:/home/username /dest/path/%0a---%0a> $ rsync --rsync-path="doas rsync" -av jrmu@jrmu.coconut.ircnow.org:/home /dest/path/%0a59c59%0a%3c 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..%0a---%0a> This will copy everything in /home into /dest/path/. @@-a@@ specifies this is an archive, @@-v@@ tells rsync to be more verbose (show files).%0a host:1626617401=38.87.162.8 author:1626616894=jrmu diff:1626616894:1626616894:=1,87d0%0a%3c (:title Rsync:)%0a%3c %0a%3c [[https://rsync.samba.org/|Rsync]] is a very useful tool for backing up files. It can be used remotely.%0a%3c %0a%3c '''WARNING''': If your filesystem is being actively written to, data corruption may occur.%0a%3c %0a%3c !! Rsync Primer%0a%3c %0a%3c OpenBSD includes its own rewrite of rsync called [[https://man.openbsd.org/openrsync|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.%0a%3c %0a%3c Here's how to back up the file /path/to/file on ircnow.org with username to the current directory:%0a%3c %0a%3c [@%0a%3c $ rsync -a username@ircnow.org:/path/to/file ./%0a%3c @]%0a%3c %0a%3c We add the option @@-a@@ for archive mode.%0a%3c %0a%3c If you have multiple files, you can use the shorthand of :/path/to/second/file:%0a%3c %0a%3c [@%0a%3c $ rsync -a username@ircnow.org:/path/to/file :/path/to/second/file ./%0a%3c @]%0a%3c %0a%3c This copies both /path/to/file and /path/to/second/file from ircnow.org to your current local directory.%0a%3c %0a%3c [@%0a%3c $ rsync -a username@ircnow.org:/path/to/file :/path/to/second/file ./%0a%3c @]%0a%3c %0a%3c We add @@-v@@ options to turn on verbosity (it will display each file copied).%0a%3c %0a%3c [@%0a%3c $ rsync username@ircnow.org:/path/to/file ./%0a%3c @]%0a%3c %0a%3c %0a%3c !! Quick Check%0a%3c %0a%3c 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:%0a%3c %0a%3c [@%0a%3c $ df -h%0a%3c Filesystem Size Used Avail Capacity Mounted on%0a%3c /dev/sd0a 1005M 111M 844M 12%25 /%0a%3c /dev/sd0k 192G 28.7G 153G 16%25 /home%0a%3c /dev/sd0d 3.9G 22.1M 3.7G 1%25 /tmp%0a%3c /dev/sd0f 12.3G 7.3G 4.4G 63%25 /usr%0a%3c /dev/sd0e 14.7G 41.2M 14.0G 0%25 /var%0a%3c @]%0a%3c %0a%3c Backing up /home will require at least 28.7G of space.%0a%3c %0a%3c %0a%3c [@%0a%3c $ rsync --rsync-path="doas rsync" -av jrmu@jrmu.coconut.ircnow.org:/home /dest/path/%0a%3c @]%0a%3c %0a%3c This will copy everything in /home into /dest/path/. @@-a@@ specifies this is an archive, @@-v@@ tells rsync to be more verbose (show files).%0a%3c %0a%3c !! Complete Functions%0a%3c %0a%3c Put the following functions at the end of ~/.profile:%0a%3c %0a%3c [@%0a%3c rsync-all () {%0a%3c echo "Backing up in $PWD: type ctrl+c to abort, enter to continue"%0a%3c read $cancel%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /" > root.dmp%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /home" > home.dmp%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /home/vmm" > vmm.dmp%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /mnt" > mnt.dmp%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /var" > var.dmp%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /var/www/htdocs" > htdocs.dmp%0a%3c ssh $1 "doas dump -0 -a -u -h 0 -f - /usr" > usr.dmp%0a%3c date > date%0a%3c md5 root.dmp home.dmp vmm.dmp mnt.dmp var.dmp htdocs.dmp usr.dmp date > md5sum%0a%3c }%0a%3c %0a%3c @@rsync-all@@ will make a complete backup of the remote system you specify.%0a%3c %0a%3c Source it, then call it on the server:%0a%3c %0a%3c [@%0a%3c $ . .profile%0a%3c $ rsync-all example.ircnow.org%0a%3c @]%0a host:1626616894=38.87.162.8