Skip to content

Instantly share code, notes, and snippets.

@shalomb
Last active July 31, 2020 21:02
Show Gist options
  • Save shalomb/5128ed10ac95788c365085068ddf49c2 to your computer and use it in GitHub Desktop.
Save shalomb/5128ed10ac95788c365085068ddf49c2 to your computer and use it in GitHub Desktop.
using rsync to backup data from aws instance
#!/bin/bash
set -eu -o pipefail
set -xv
ssh_args='-i ./aws-jira.pem -o StrictHostKeyChecking=no -o PubkeyAuthentication=yes'
[email protected]
# Stop services so our backups are integral
ssh "$ssh_args" "$ssh_host" '
sudo service postgresql start;
sudo sh -c "sudo -u postgres pg_dump jiradb > /var/backups/jiradb.pgdump";
sudo service postgresql stop;
sudo service nginx stop;
sudo service hhvm stop;
sudo service jira stop;
' || true
# backup the select directories
for dir in \
/etc/nginx/ \
/home/ubuntu/dz2/ \
/home/ubuntu/web/ \
/opt/ \
/etc/init.d/ \
/var/atlassian/ \
/var/lib/postgresql/ \
/var/log/nginx/ \
/var/log/postgresql/ \
/var/backups/ \
; do
mkdir -p "backup/${dir}"
rsync -e "ssh $ssh_args" -avPHLAX --rsync-path="sudo rsync" \
"$ssh_host":"${dir}/" backup/"${dir}/";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment