Created
February 16, 2021 03:26
-
-
Save ShaRose/c60018f7642edbbaf0b6d3c5adc82c11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Written for EdgeOS, probably works on vyos and vyatta as well. | |
# Writes full (tar based) backup to /tmp, then uploads it to each of the commit archive locations. | |
# Doesn't do cycling or anything: Just router-full-backup-2021-02-16.tar.gz fired at where you store commits every whenever | |
# Things to do if I weren't lazy: | |
# Make it a package, with its own configuration trees | |
# Encrypt each backup using public key or private key crypto: your choice! | |
# Make it cycle backups automatically | |
# Set up scheduling so you don't have to do it yourself | |
# Sanity checks: Not MORE, but sanity checks in general | |
# Stop being lazy and do all of the above | |
# Set up files we don't want backed up | |
cat << 'EOF' > /tmp/backup-blocklist | |
config/dhcpd.leases | |
config/dhcpdv6.leases | |
EOF | |
# Here's the filename we use | |
tmp_filename="$(hostname)-full-backup-$(date -I).tar.gz" | |
# Now the working bits | |
# Do the backup | |
tar -cz -X /tmp/backup-blocklist -f "/tmp/$tmp_filename" /config 2>/dev/null | |
# We should probably verify it's valid... but meh if this fails you have bigger worries | |
# Now upload it to all the commit locations | |
while read archive_path || [[ $archive_path ]]; do | |
echo -n "Uploading to $archive_path..." | |
curl -s -k -T "/tmp/$tmp_filename" "$archive_path" | |
# Should I make sure this works? Nah | |
echo "Done." | |
done </opt/vyatta/config/active/system/config-management/commit-archive/location/node.val | |
# Now clean up after ourselves | |
rm /tmp/backup-blocklist | |
rm "/tmp/$tmp_filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment