Skip to content

[FreeBSD] Basic backups

September 18, 2022 | 09:03 PM

Just stashing my primitive 🔨 backup script so I don’t forget where it is and how it works. It needs some consolidation and optimization still.

I’m planning to put this type of stuff into a boostrap repo on GitHub eventually…

#!/bin/sh
#/etc/periodic/weekly/backup 

# check that the drive is mounted
if mount | grep /media/MyBook > /dev/null; then
    rsync -avX --stats --delete \
    -exclude="/dev/" \
    -exclude="/entropy/" \
    -exclude="/proc/" \
    -exclude="/tmp/" \
    -exclude="/mnt/" \
    -exclude="/media/" \
    -exclude="/usr/home/jv/Sync/" \
     /media/MyBook/cube-backup

    # update the motd with the latest (include snapshots)
    date > /var/log/last_backup
    echo -n "Last system backup:   " >  /etc/motd.template
    cat /var/log/last_backup         >> /etc/motd.template
    echo ""                          >> /etc/motd.template
    echo -n "Last system snapshot: " >> /etc/motd.template
    cat /var/log/last_snapshot       >> /etc/motd.template
else
    last=`cat /var/log/last_backup`
    echo -n "Last system backup:   " >  /etc/motd.template
    echo $last                       >> /etc/motd.template
    echo -n "  - BACKUP  FAILED -  " >> /etc/motd.template
    date                             >> /etc/motd.template
    echo -n "Last system snapshot: " >> /etc/motd.template
    cat /var/log/last_snapshot       >> /etc/motd.template
fi
#!/bin/sh
#/etc/periodic/daily/snapshot
# create daily snapshots

dow=`date +"%a"`
# destroy last week's snap
zfs destroy "zroot@${dow}"
# make today's
zfs snapshot "zroot@${dow}"

# update the motd with the latest (include backups)
date > /var/log/last_snapshot
echo -n "Last system backup:   " >  /etc/motd.template
cat /var/log/last_backup         >> /etc/motd.template
echo ""                          >> /etc/motd.template
echo -n "Last system snapshot: " >> /etc/motd.template
cat /var/log/last_snapshot       >> /etc/motd.template