diff --git a/README.md b/README.md index 1fe3c48..c85c25b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Edit `/config/user-data/edgerouter-backup.conf` with your information: SSH_KEYFILE=/config/user-data/backup_user_private.key SSH_USER=username SSH_HOST=host + SSH_PORT=port # Path to git repo on SSH_HOST REPO_PATH=\~/edgerouter-backups diff --git a/config/user-data/edgerouter-backup.conf b/config/user-data/edgerouter-backup.conf index a012d13..7377776 100644 --- a/config/user-data/edgerouter-backup.conf +++ b/config/user-data/edgerouter-backup.conf @@ -6,6 +6,7 @@ DEFAULT_COMMIT_MESSAGE="Auto commit by edgerouter-backup on $HOSTNAME" # SSH Information SSH_USER= SSH_HOST= +SSH_PORT=22 # Path to private key for SSH_USER SSH_KEYFILE=/config/user-data/${SSH_USER}_private.key diff --git a/config/user-data/hooks/03-edgerouter-backup.sh b/config/user-data/hooks/03-edgerouter-backup.sh index e298294..13d4d4e 100644 --- a/config/user-data/hooks/03-edgerouter-backup.sh +++ b/config/user-data/hooks/03-edgerouter-backup.sh @@ -38,13 +38,13 @@ sudo find /config/* | grep -v "/config/dhcpd.leases" | xargs tar cf /tmp/edgerou # 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.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 +sudo scp -P $SSH_PORT -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 -P $SSH_PORT -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.tar | sudo ssh -p $SSH_PORT -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 +sudo ssh -p $SSH_PORT -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