1,定时备份文件,并删除7天前的文件,以防止占用硬盘空间过大
2,设置mysqlbak.sh自动执行
root登录
#crontab -u root -e
0 0 * * * /root/leancare/mysqlbak.sh
保存退出
1,定时备份文件,并删除7天前的文件,以防止占用硬盘空间过大
2,设置mysqlbak.sh自动执行
root登录
#crontab -u root -e
5 23 * * * /root/mysql_backup.sh >> /root/cronjob-log.txt
保存退出
#!/bin/bash
# Name:mysqlbak.sh
# This is a ShellScript For Auto DB BackUp and Delete old Backup
#
backupdir=/root/leancare/database
time=` date +%Y%m%d `
tar -cvf ./leancare$time.tar /var/lib/mysql/leancare
mv leancare$time.tar $backupdir
#
find $backupdir -name "leancare*.tar" -type f -mtime +7 -exec rm -f {} \;
2,设置mysqlbak.sh自动执行
root登录
#crontab -u root -e
0 0 * * * /root/leancare/mysqlbak.sh
保存退出
1,定时备份文件,并删除7天前的文件,以防止占用硬盘空间过大
#! /bin/bash
#
#Daily backup for MySQL database.
#
# Version: 0.1, 2010-05-04
# Author: David Ding, Eric Yuan
#
#
# crontab -e
# 0 9 * * * /root/mysql_backup.sh
#
PATH=$PATH:.
export PATH
# Command setup
MYSQL_DUMP="$(which mysqldump)"
GZIP="$(which gzip)"
MYSQL_USER="myuser"
MYSQL_PASSWORD="myuser"
MYSQL_HOST="localhost"
# Backup&DB setup
MYSQL_BACKUP_DIR="/var/mysql/data/backup"
DBS="leancare"
# check backup directory
[ ! -d $MYSQL_BACKUP_DIR ] && mkdir -p $MYSQL_BACKUP_DIR
### Start MySQL Backup ###
for db in $DBS
do
file=$MYSQL_BACKUP_DIR/$db-$(date +"%Y%m%d.sql").gz
$MYSQL_DUMP -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $db | $GZIP -9 > $file
done
2,设置mysqlbak.sh自动执行
root登录
#crontab -u root -e
5 23 * * * /root/mysql_backup.sh >> /root/cronjob-log.txt
保存退出