Skip to content

自动备份Web+Mysql -> Rclone/GoogleDrive+FTP

用的是大佬的 https://teddysun.com/469.html

特点

1、支持 MySQL/MariaDB/Percona 的数据库全量备份或选择备份;
2、支持指定目录或文件的备份;
3、支持加密备份文件(需安装 openssl 命令,可选)
4、支持上传至 Google Drive(需先安装 rclone 并配置,可选);
5、支持在删除指定天数本地旧的备份文件的同时,也删除 Google Drive 上的同名文件(可选)。

安装

apt install -y openssl unzip
wget --no-check-certificate https://github.com/teddysun/across/raw/master/backup.sh
chmod +x backup.sh

修改主要的变量 在 #### END OF CONFIG 这句之前的所有变量都值得过一下

# 如果需要加密的话
# Encrypt flag (true: encrypt, false: not encrypt)
ENCRYPTFLG=true

# WARNING: KEEP THE PASSWORD SAFE!!!
# The password used to encrypt the backup
# To decrypt backups made by this script, run the following command:
# openssl enc -aes256 -in [encrypted backup] -out decrypted_backup.tgz -pass pass:[backup password] -d -md sha1
BACKUPPASS="JustForThisScript_Pa55w0rd1_LP1RC"

# Directory to store backups
LOCALDIR="/opt/backups/"

# Temporary directory used during backup creation
TEMPDIR="/opt/backups/temp/"

# File to log the outcome of backups
LOGFILE="/opt/backups/backup.log"

# OPTIONAL: If you want backup MySQL database, enter the MySQL root password below
# 从宝塔上可以找到
MYSQL_ROOT_PASSWORD="Mysql_Root_Pass55w0rd1"

# Below is a list of MySQL database name that will be backed up
# If you want backup ALL databases, leave it blank.
MYSQL_DATABASE_NAME[0]=""

# Below is a list of files and directories that will be backed up in the tar backup
# For example:
# File: /data/www/default/test.tgz
# Directory: /data/www/default/test
BACKUP[0]="/www"
# BACKUP[0]="/another_folder_to_backup"

# Number of days to store daily local backups (default 7 days)
LOCALAGEDAILIES="3650"

# Rclone remote name
RCLONE_NAME="od_xyz_e3m1024"

# Rclone remote folder name (default "")
RCLONE_FOLDER="_bak_bwh229"

# Upload to FTP server flag (true: upload, false: not upload)
FTP_FLG=false

# Upload to RCLONE server flag (true: upload, false: not upload)
RCLONE_FLG=true

# FTP server
# OPTIONAL: If you want upload to FTP server, enter the Hostname or IP address below
FTP_HOST=""

# FTP username
# OPTIONAL: If you want upload to FTP server, enter the FTP username below
FTP_USER=""

# FTP password
# OPTIONAL: If you want upload to FTP server, enter the username's password below
FTP_PASS=""

# FTP server remote folder
# OPTIONAL: If you want upload to FTP server, enter the FTP remote folder below
# For example: public_html
FTP_DIR=""
ln -s /root/gd_stanford/_bak/bwh229 /opt/backups

Crontab – 自动执行

crontab -e
# 加入
# run every wed 0110am
10 1 * * 3  /root/backup.sh

解密解压


openssl enc -aes256 -in [ENCRYPTED BACKUP] -out decrypted_backup.tgz -pass pass:[BACKUPPASS] -d -md sha1

tar -zxPf [DECRYPTION BACKUP FILE]
# 解释一下参数 -P:
#tar 压缩文件默认都是相对路径的。加个 -P 是为了 tar 能以绝对路径压缩文件。因此,解压的时候也要带个 -P 参数。

Leave a Reply

Your email address will not be published.