mirror of https://github.com/einverne/dotfiles.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
7 years ago
|
#!/bin/bash
|
||
|
|
||
7 years ago
|
# 发邮件方式备份网站数据
|
||
|
# 脚本会创建一个压缩包,包含备份的目录和MySQL 数据库备份
|
||
7 years ago
|
# Feel free to use this script wherever you want, however you want. We produce open source, GPLv2 licensed stuff.
|
||
|
# https://theme.fm/a-shell-script-for-a-complete-wordpress-backup/
|
||
|
|
||
7 years ago
|
# 设置备份文件名
|
||
7 years ago
|
NOW=$(date +"%Y-%m-%d-%H-%M")
|
||
|
FILE="www.einverne.info.$NOW.tar"
|
||
|
GZ_FILE=$FILE.gz
|
||
7 years ago
|
# 备份文件压缩包存放路径
|
||
7 years ago
|
BACKUP_DIR="/root/backups"
|
||
7 years ago
|
# 需要备份的路径文件夹
|
||
7 years ago
|
WWW_DIR="/var/www/www.einverne.info/html"
|
||
7 years ago
|
# 接受者邮箱
|
||
7 years ago
|
EMAIL_ADDR="[email protected]"
|
||
|
|
||
7 years ago
|
# MySQL 数据库相关配置
|
||
7 years ago
|
DB_USER=""
|
||
|
DB_PASS=""
|
||
|
DB_NAME=""
|
||
|
DB_FILE="www.einverne.info.$NOW.sql"
|
||
|
|
||
7 years ago
|
# 将Tar压缩包内内容,分别保存到 html 和 database 两个文件夹下
|
||
7 years ago
|
WWW_TRANSFORM='s,^var/www/www.einverne.info/html,html,'
|
||
|
DB_TRANSFORM='s,^root/backups,database,'
|
||
|
|
||
|
# 以上内容需要自定义
|
||
|
|
||
7 years ago
|
mkdir -p $BACKUP_DIR
|
||
7 years ago
|
# Create the archive and the MySQL dump
|
||
|
tar -cvf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR
|
||
|
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/$DB_FILE
|
||
|
|
||
|
# Append the dump to the archive, remove the dump and compress the whole archive.
|
||
|
tar --append --file=$BACKUP_DIR/$FILE --transform $DB_TRANSFORM $BACKUP_DIR/$DB_FILE
|
||
|
rm $BACKUP_DIR/$DB_FILE
|
||
|
gzip -9 $BACKUP_DIR/$FILE
|
||
|
|
||
|
# Split file and send by email
|
||
|
split -b 5M $BACKUP_DIR/$GZ_FILE $BACKUP_DIR/$GZ_FILE.
|
||
|
rm $BACKUP_DIR/$GZ_FILE
|
||
|
|
||
|
for filename in $BACKUP_DIR/*; do
|
||
|
echo $filename
|
||
|
echo "backup" | mutt -s "$GZ_FILE" $EMAIL_ADDR -a $filename
|
||
|
done
|
||
|
|
||
|
rm -rf $BACKUP_DIR
|