Created
October 8, 2012 08:23
-
-
Save rubyonrailsworks/3851382 to your computer and use it in GitHub Desktop.
MagicOrders DBBAK SHELL SCRIPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 2 * * * `/bin/sh /bin/dbbak.sh` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBName=magic_orders | |
MYSQLUser=root | |
MYSQLPassword=root | |
BackupPath=/var/backups/magic_orders/ | |
TIMESTAMP=`date "+%Y-%m-%d-%H"` | |
MYSQLBACKFILE="mysql_${TIMESTAMP}" | |
MONGOBACKDIR="mongo_${TIMESTAMP}" | |
MYSQLSql="${MYSQLBACKFILE}.sql" | |
MYSQLZip="${MYSQLBACKFILE}.zip" | |
cd ${BackupPath}; | |
#dump MySQL file | |
mysqldump --user=${MYSQLUser} --password=${MYSQLPassword} ${DBName} > ${MYSQLSql}; | |
zip -m ${MYSQLZip} ${MYSQLSql}; #压缩并删除源文件 | |
#dump Mongo file | |
mongodump -d ${DBName} -o ${MONGOBACKDIR} | |
zip -r -m ${MONGOBACKDIR}".zip" ${MONGOBACKDIR} #压缩并删除源文件 | |
#rm old files | |
find ${BackupPath} -mtime +10 -exec rm {} \; #保留10天内的压缩文件 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment