数据备份基本思路:
1,找到源数据存储的路径,
2,写定时脚本将源数据复制到新的备份路径下面。
设置定时执行脚本任务
crontab -e
[root@tlanx1 redis]# crontab -e
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
45 02 * * * /home/backup/mysql/mysql.sh
00 02 * * * /home/backup/redis/redis.sh
15 02 * * * /home/backup/mongobd/mongobd.sh
#32 23 * * * /home/backup/gitlab/gitlab.sh
42 23 * * * gitlab-rake gitlab:backup:create
详细设置过程请参考:
https://www.cnblogs.com/emily1130/p/7345842.html
备份mysql数据脚本
#!/bin/bash
BACKUP=/home/backup/mysql/
DATETIME=$(date +%Y-%m-%d_%H%M%S)
HOST=localhost
DB_USER=root
DB_PW='Kz^D$z0KDWG1NEQ!'
[ ! -d "${BACKUP}/$DATETIME" ] && mkdir -p "${BACKUP}/$DATETIME"
mysqldump -u${DB_USER} -p${DB_PW} --host=$HOST --all-databases | gzip > ${BACKUP}/$DATETIME/alldb.sql.gz
cd $BACKUP
tar -zcvf $DATETIME.tar.gz $DATETIME
rm -rf ${BACKUP}/$DATETIME
find $BACKUP -mtime +7 -name "*.tar.gz" -exec rm -rf {} \;
redis数据备份
#!/bin/bash
BACKUP=/home/backup/redis/
RES=/home/redis/data
DATETIME=$(date +%Y-%m-%d_%H%M%S)
[ ! -d "${BACKUP}/$DATETIME" ] && mkdir -p "${BACKUP}/$DATETIME"
cp -r ${RES} ${BACKUP}/$DATETIME
cd ${BACKUP}
tar -zcvf $DATETIME.tar.gz $DATETIME
rm -rf ${BACKUP}/$DATETIME
find ${BACKUP} -mtime +7 -name "*.tar.gz" -exec rm -rf {} \;