Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aliyun Backup
#! /bin/bash
DEST_DIR=$PWD/backup/daily/database/
COMPRESSED_DIR=$PWD/backup/daily/database-compressed/
OSSPTH=oss://<OSS_BUCKET>
DATABASE_NAME=<Database_Name>
MYSQL_USER=<Database_User>
MYSQL_PASS=<Database_Password>
cd $DEST_DIR
mysqldump -u${MYSQL_USER} -p${MYSQL_PASS} ${DATABASE_NAME} > daily-db-$(date +%Y%m%d).sql
tar -cjf $COMPRESSED_DIR/Daily-db-$(date +%Y%m%d).tar.bz2 daily-db-$(date +%Y%m%d).sql -C $DEST_DIR .
ossutil64 cp $COMPRESSED_DIR/Daily-db-$(date +%Y%m%d).tar.bz2 $OSSPATH --meta X-oss-Storage-Class:Standard
#! /bin/bash
SOURCE_DIR=<Backup_Files_URL>
DEST_DIR=$PWD/backup/daily/code/
COMPRESSED_DIR=$PWD/backup/daily/compressed/
OSSPATH=oss://<OSS_PATH>
rsync -az --delete $SOURCE_DIR $DEST_DIR
cd $DEST_DIR
tar -cjf $COMPRESSED_DIR/Daily-$(date +%Y%m%d).tar.bz2 . -C $DEST_DIR .
ossutil64 cp $COMPRESSED_DIR/Daily-$(date +%Y%m%d).tar.bz2 $OSSPATH --meta X-oss-Storage-Class:Standard
#! /bin/bash
SOURCE_DIR=<Backup_Files_URL>
DEST_DIR=$PWD/backup/monthly/code/
COMPRESSED_DIR=$PWD/backup/monthly/compressed/
OSSPATH=oss://<OSS_PATH>
rsync -az --delete $SOURCE_DIR $DEST_DIR
cd $DEST_DIR
tar -cjf $COMPRESSED_DIR/Monthly-$(date +%Y%m%d).tar.bz2 . -C $DEST_DIR .
ossutil64 cp $COMPRESSED_DIR/Monthly-$(date +%Y%m%d).tar.bz2 $OSSPATH --meta X-oss-Storage-Class:Archive
#! /bin/bash
SOURCE_DIR=$PWD/backup/daily/code/
DEST_DIR=$PWD/backup/weekly/code/
COMPRESSED_DIR=$PWD/backup/weekly/compressed/
OSSPATH=oss://<OSS_BUCKET>
rsync -az --delete $SOURCE_DIR $DEST_DIR
cd $DEST_DIR
tar -cjf $COMPRESSED_DIR/Weekly-$(date +%Y%m%d).tar.bz2 . -C $DEST_DIR .
ossutil64 cp $COMPRESSED_DIR/Weekly-$(date +%Y%m%d).tar.bz2 $OSSPATH --meta X-oss-Storage-Class:IA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment