Backing Up on Ubuntu Server
I have several VM's that are managed through Proxmox and therefore can be backed up pretty easily. The whole VM is backed up to a separate disk which has saved me several times already.
However, I have another machine that is stand alone and runs Ubuntu 20.04 LTS as its primary OS. Which means there's no built-in way to back it up like there is in Proxmox. So what am I to do?
What I eventually settled on was routine backups to a new dataset on my NAS. I wrote a simple script that tars a specific folder on my server, sends it to the NAS via a mounted NFS share (can be sent other ways too) and then deletes the tared file from the server. It's a little messy, but it gets the job done. I then set up a cron job to run the script at a time of my choosing.
#!/bin/bash
now=$(date +"%Y_%m_%d")
tar cfj compose-files_backup_$now.tar.bz2 --directory=/home/user compose-files
rsync --remove-source-files -a --no-g /home/user/scripts/composefiles_backup_$now.tar.bz2 /nfs/docker-vm2-backups/
Here is the script in question. I set the $now variable so that I could automatically name the backup files and make it easier to choose which one to use later. I plan to run this once a week so I didn't need anything more specific than the day it's from. As it is right now, the backups will build up with none being deleted which could become a problem in the future, but right now it's not an issue.
I've made several of these scripts for the various folder that I want to have backed up and added those as cron jobs as well. This way I can control the backups that are done depending on the server and service. This machine primarily runs docker with those docker containers data mounted inside of their respective folders. By backing up one folder I can be sure that my data will be safe if the machine happens to go haywire.
This is not a perfect solution. In fact there are things I want to improve about it. I'd like to have another offsite location that I can back up to and preferably another on sight one. By doing that I would then be confident that my data is sufficiently backed up.