Created
February 19, 2022 12:56
-
-
Save selevit/bdad415adc19c50111be2d7ca1dbe2a3 to your computer and use it in GitHub Desktop.
Backup EdgeOS config to S3
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/vbash | |
set -e | |
source /opt/vyatta/etc/functions/script-template | |
# Save configuration to backups | |
NOW=`date -I'seconds'` | |
BACKUP_ROOT="/backup" | |
CONFIG_FILE="edgerouter_config_${NOW}.boot" | |
save "${BACKUP_ROOT}/${CONFIG_FILE}" | |
# Sync backups to s3 | |
echo "Uploading to s3" | |
BACKUP_S3_BUCKET="backup.edgerouter.lan" | |
export AWS_ACCESS_KEY_ID="xxx" | |
export AWS_SECRET_ACCESS_KEY="xxx" | |
/usr/local/bin/aws s3 sync --delete "$BACKUP_ROOT" "s3://$BACKUP_S3_BUCKET/" | |
# Delete old backups | |
NUMBER_OF_BACKUPS=`ls "${BACKUP_ROOT}" | wc -l` | |
if [[ "$NUMBER_OF_BACKUPS" -gt 30 ]]; then | |
echo "Deleting backups older than 30 days" | |
find "${BACKUP_ROOT}" -mtime +30 -type f -delete | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment