I cobbled together a simple backup script that basically mounts my nas drive and then exports all the jails to the nas. It also only keeps so many copies so as to not run out of space I think about 30 days worth. It also backups certain files from the host too.
I'll share it here but be warned others will say that I should do things differently but it's simple like me and just works. Also YES I have recovered a backup before when something went wrong whilst tinkering with my snac install last year and it recovered just fine.
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# Mount nas drive
mount_smbfs -T 60 -R 20 -I x.x.x.x //beastie@beastie/Beastie /mnt/nas1
if mount | grep /mnt/nas1 > /dev/null; then
echo "smb mount successfull."
else
echo "smb mount failed."
exit
fi
# Variables
backuppath=/mnt/nas1/backup
mkdir -p "$backuppath"/host
mkdir -p "$backuppath"/jails
# Backup all Bastille jails to backup path
for jail in $(bastille list jail)
do
echo "Backing up $jail"
bastille export --xz "$jail" "$backuppath"/jails
done
# Backup Host files
files="/boot/loader.conf
/etc/rc.conf
/etc/pf.conf
/etc/nsmb.conf
/etc/ssh/sshd_config
/usr/local/etc/doas.conf
/usr/local/etc/fail2ban/jail.d/ssh-pf.local
/usr/local/etc/bastille/bastille.conf"
tar cvf "$backuppath"/host/beastie-$(date "+%d%m%Y-%H%M%S").tar.xz $(echo "$files")
# Delete all files older than 31 days
# Or replace -exec rm {} \; with -print to test it
find "$backuppath" -mtime +31 -type f -exec rm {} \;
# Unmount the nas drive
umount /mnt/nas1
Yes it I could improve it and probably will eventually but each to their own. 😉
#FreeBSD
