This was in my ~/notes/ but it got wrapped in html and now it's here for all public consumption.

dump and restore are both in the base OpenBSD system. Despite being old, they are still very useful. My offsite backups I do through TarSnap; however, I also keep local backups on external drives.

Creating dumps

This would be a great place to use cron if you have drives which remain attached. However, I only occasionally have my external drive attached, so I still perform my dumps manually.

The dump(8) manpage explains better some variety of how you may choose to perform your dumps. Since all of the different levels of my dumps go to the same drive and I am not concerned about wearing out tapes by having too many writes, my order is purely sequential. I create a 0, then 1-7, then repeat 1-7. Since my dumps are at-will and manual, I put the date in the filename as well as the level of the dump. My paths are based on hostname and partition being dumped.

# doas to elevate to root for full read of /home contents
     # dump command
          #level 0 dump, bypass tape-length considerations, update /etc/dumpdates, and dump to the filepath provided
                # mountpoint for dump disk, hostname of system, date of dump, level of dump
                                                 # partition being dumped
doas dump -0auf /mnt/dump/maleah/home/20201020-0 /home
        

Thus, something similar to have in cron would be like:

~ 1~6 * * 1 /usr/bin/doas /sbin/dump -1auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump1 /home
~ 1~6 * * 2 /usr/bin/doas /sbin/dump -2auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump2 /home
~ 1~6 * * 3 /usr/bin/doas /sbin/dump -3auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump3 /home
~ 1~6 * * 4 /usr/bin/doas /sbin/dump -4auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump4 /home
~ 1~6 * * 5 /usr/bin/doas /sbin/dump -5auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump5 /home
~ 1~6 * * 6 /usr/bin/doas /sbin/dump -6auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump6 /home
~ 1~6 * * 7 /usr/bin/doas /sbin/dump -7auf /mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump7 /home
      

Note: The extension here has no consequence at all and is just my own preference.

To a remote destination

Since it's been mentioned elsewhere, OpenBSD's dump also supports remote targets, like the old 'rdump'. This is as simple as giving an argument to "-f" which is a remote Host:Path. This presumes you have working ssh connectivity to the remote host.

/usr/bin/doas /sbin/dump -1auf mybackuphost:/mnt/dump/maleah/$(hostname -s)/$(date +%Y%m%d).dump1 /home

Since this requires rmt(8) on the remote host (and you may not have this enabled) you can also pipe through ssh as similarly:

/usr/bin/doas /sbin/dump -1auf - /home | ssh mybackuphost "cat > /mnt/dump/maleah/maleah.home.dayid.org/$(date +%Y%m$d).dump1"

Restoring files from dump

To restore files from a dump (here, just a file on a removable disk). Here, I wanted to restore ".bash_history". Restoring a file extracts it to the full path of where it is within the dump. Thus, it makes life much simpler if you start dump from the same path that the dump is for (e.g., if the dump is for /home, then run restore from /home) or better off, restore to a separate/new path and then copy/move/rsync files back into place (e.g., extract/restore to /mnt/RESTORE and then rsync /mnt/RESTORE/restored-file-path /real/file/path/

An interactive restore example

I started by opening the newest dump file I had:

$ restore -i -f /mnt/dump/maleah/home/20201012.dump4
restore > ls
    .:
    cameraftp/ dayid/ erin/ gitd/ www/
restore > cd dayid                      # go to where the file was
restore > add .bash_history             # add this file to the list of files to be restored
restore > extract                       # extract all added files
        

A non-interactive restore example

This will list all_ files in the dump - useful to | grep

$ restore -t -f /mnt/dump/maleah/home/20201012.dump4

Since I know the path though I use -t (as "test") to ensure the file exists there. The path is relative since this dump was of /home

$ restore -t -f /mnt/dump/maleah/home/20201012.dump4 dayid/.bash_history

Extract the file:

$ restore -x -f /mnt/dump/maleah/home/20201012.dump4 dayid/.bash_history
    restore: ./dayid: File exists # this shows up because the directory already exists, so restore is not creating it as it usually would.
    You have not read any tapes yet.
    Unless you know which volume your file(s) are on you should start with the last volume and work towards the first.
    Specify next volume #: 1
    set owner/mode for '.'? [yn] y