Skip to content

Commit

Permalink
.tar file was not actually being gzip'd. Config file changed to speci…
Browse files Browse the repository at this point in the history
…fy $FNAME_BASE without an extension.
  • Loading branch information
None committed Jul 6, 2017
1 parent 541575d commit 2907065
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion config/user-data/edgerouter-backup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ FNAME_BASE=$HOSTNAME

FNAME_CONFIG=$FNAME_BASE.config.conf
FNAME_CLI=$FNAME_BASE.commands.conf
FNAME_BACKUP=$FNAME_BASE.backup.tar.gz

# Base filename, no extension!
FNAME_BACKUP=$FNAME_BASE.backup
14 changes: 7 additions & 7 deletions config/user-data/hooks/03-edgerouter-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ GIT_COMMIT_MSG="$COMMIT_CMT | by $USER | via $COMMIT_VIA | $TIME"

# Remove temporary files
#echo "edgerouter-backup: Removing temporary files"
sudo rm /tmp/edgerouter-backup-$FNAME_CONFIG &> /dev/null
sudo rm /tmp/edgerouter-backup-$FNAME_CLI &> /dev/null
sudo rm /tmp/edgerouter-backup-$FNAME_BACKUP &> /dev/null
sudo rm /tmp/edgerouter-backup-$FNAME_CONFIG &> /dev/null
sudo rm /tmp/edgerouter-backup-$FNAME_CLI &> /dev/null
sudo rm /tmp/edgerouter-backup-$FNAME_BACKUP.tar &> /dev/null


# Generate temporary config files
sudo cli-shell-api showConfig --show-active-only --show-ignore-edit --show-show-defaults > /tmp/edgerouter-backup-$FNAME_CONFIG
sudo cli-shell-api showConfig --show-commands --show-active-only --show-ignore-edit --show-show-defaults > /tmp/edgerouter-backup-$FNAME_CLI
sudo find /config/* | grep -v "/config/dhcpd.leases" | xargs tar cf /tmp/edgerouter-backup-$FNAME_BACKUP &> /dev/null
sudo find /config/* | grep -v "/config/dhcpd.leases" | xargs tar cf /tmp/edgerouter-backup-$FNAME_BACKUP.tar &> /dev/null

# Push config files
echo "edgerouter-backup: Copying backup files to $SSH_USER@$SSH_HOST:$REPO_PATH"
sudo scp -q -i $SSH_KEYFILE -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/edgerouter-backup-$FNAME_CONFIG $SSH_USER@$SSH_HOST:$REPO_PATH/$FNAME_CONFIG > /dev/null
sudo scp -q -i $SSH_KEYFILE -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/edgerouter-backup-$FNAME_CLI $SSH_USER@$SSH_HOST:$REPO_PATH/$FNAME_CLI > /dev/null
sudo cat /tmp/edgerouter-backup-$FNAME_BACKUP | sudo ssh -q -i $SSH_KEYFILE -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST "gzip -cnq9 > $REPO_PATH/$FNAME_BACKUP" > /dev/null
sudo cat /tmp/edgerouter-backup-$FNAME_BACKUP.tar | sudo ssh -q -i $SSH_KEYFILE -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST "gzip -cnq9 > $REPO_PATH/$FNAME_BACKUP.tar.gz" > /dev/null

# git commit and git push on remote host
echo "edgerouter-backup: Triggering 'git commit'"
sudo ssh -q -i $SSH_KEYFILE -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST 'bash -s' << ENDSSH > /dev/null
cd $REPO_PATH
git add $REPO_PATH/$FNAME_CONFIG
git add $REPO_PATH/$FNAME_CLI
git add $REPO_PATH/$FNAME_BACKUP
git add $REPO_PATH/$FNAME_BACKUP.tar.gz
git commit -m "$GIT_COMMIT_MSG"
git push
ENDSSH

echo "edgerouter-backup: Complete"
echo "edgerouter-backup: Complete"

0 comments on commit 2907065

Please sign in to comment.