Skip to content

Instantly share code, notes, and snippets.

@barryvdh
Last active August 24, 2017 07:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryvdh/f6c83718b9f587955ce9 to your computer and use it in GitHub Desktop.
Save barryvdh/f6c83718b9f587955ce9 to your computer and use it in GitHub Desktop.
Move backups to AWS
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
chmod 755 /usr/local/bin/aws
  • Create the file in the custom scripts directory:
wget https://gist.github.com/barryvdh/f6c83718b9f587955ce9/raw/10b161ea1d52f12d6ffa0a4c54f3dceab25de45e/user_backup_post.sh -P /usr/local/directadmin/scripts/custom
  • Edit the bucket + credentials, make it executable
vi /usr/local/directadmin/scripts/custom/user_backup_post.sh
chmod 755 /usr/local/directadmin/scripts/custom/user_backup_post.sh
  • Create a backup in '/home/(reseller)/admin_backups/aws' (or subdirectory)
#!/bin/sh
#############
#set the backup credentials
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=eu-central-1
#where do you want to save the AWS copy?
SAVE_PATH=s3://fruitcake-backup/${HOSTNAME}
TMP_DIR=aws
#############
BACKUP_DB=
BACKUP_MEDIA=
if [ "$1" = "--db" ]; then
BACKUP_DB=1
elif [ "$1" = "--media" ]; then
BACKUP_MEDIA=1
else
BACKUP_DB=1
BACKUP_MEDIA=1
fi
cd $(dirname "$0")
mkdir -p $TMP_DIR
if [ "$BACKUP_DB" = 1 ]; then
magerun db:dump $TMP_DIR/database.sql --strip='@stripped' -n
/usr/local/bin/aws s3 mv $TMP_DIR/database.sql $SAVE_PATH/database.sql
fi
if [ "$BACKUP_MEDIA" = 1 ]; then
magerun media:dump $TMP_DIR/media.zip --strip -n
/usr/local/bin/aws s3 mv $TMP_DIR/media.zip $SAVE_PATH/media.zip
fi
#!/bin/sh
#############
#set the backup credentials
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=eu-central-1
#where do you want to save the AWS copy?
SAVE_PATH=s3://fruitcake-backup/${HOSTNAME}
#set this as needed
RESELLER=admin
#############
BACKUP_PATH=`echo $file | cut -d/ -f1,2,3,4,5`
REQUIRED_PATH=/home/$RESELLER/admin_backups/aws
if [ "$BACKUP_PATH" = "$REQUIRED_PATH" ]; then
NEW_FILE=${SAVE_PATH}/`echo $file | cut -d/ -f6-`
/usr/local/bin/aws s3 mv $file $NEW_FILE
fi
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment