Last active
July 30, 2021 00:05
-
-
Save tdtgit/f4fb1844b17efd294de81950c4ddf43e to your computer and use it in GitHub Desktop.
Rclone Backup 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
#!/bin/bash | |
#v=1.0 | |
SERVER_NAME= | |
TIMESTAMP=$(date +"%F-%H-%M") | |
SECONDS=0 | |
BACKUP_DIR="/root/backup/$TIMESTAMP" | |
MYSQL=/usr/bin/mysql | |
MYSQL_USER=root | |
MYSQL_PASSWORD= | |
MYSQLDUMP=/usr/bin/mysqldump | |
################# MySQL Backup ################# | |
mkdir -p "$BACKUP_DIR/mysql" | |
echo "Starting Backup Database"; | |
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"` | |
for db in $databases; do | |
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz" | |
done | |
/usr/sbin/rclone move $BACKUP_DIR "Driveremote:$SERVER_NAME/$TIMESTAMP" >> /var/log/rclone.log 2>&1 | |
rm -rf $BACKUP_DIR/* | |
echo "Finished Backup Database"; | |
echo '-------------------------------------'; | |
################# Website Backup ################# | |
echo "Starting Backup Website"; | |
for D in /var/www/*; do | |
if [ -d "${D}" ]; then | |
domain=${D##*/} | |
echo "-- Starting backup "$domain; | |
zip -r $BACKUP_DIR/$domain.zip /var/www/$domain/htdocs/* -q -x /var/www/$domain/htdocs/wp-content/cache/**\* | |
/usr/sbin/rclone move $BACKUP_DIR "Driveremote:$SERVER_NAME/$TIMESTAMP" >> /var/log/rclone.log 2>&1 | |
rm -rf $BACKUP_DIR/* | |
echo "-- Backup done "$domain; | |
fi | |
done | |
echo "Finished Backup Website"; | |
echo '-------------------------------------'; | |
################# Nginx Configuration Backup ################# | |
echo "Starting Backup Nginx Configuration"; | |
cp -r /etc/nginx/ $BACKUP_DIR/nginx/ | |
/usr/sbin/rclone move $BACKUP_DIR "Driveremote:$SERVER_NAME/$TIMESTAMP" >> /var/log/rclone.log 2>&1 | |
echo "Finished Backup Nginx Configuration"; | |
echo '-------------------------------------'; | |
#/usr/sbin/rclone -q --min-age 6m delete "Driveremote:$SERVER_NAME" #Remove all backups older than 2 week | |
#/usr/sbin/rclone -q --min-age 6m rmdirs "Driveremote:$SERVER_NAME" #Remove all empty folders older than 2 week | |
rm -rf /root/backup/* | |
duration=$SECONDS | |
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Giới thiệu
Script backup bằng Rclone sửa mới từ code của bác Luân canhme.com
Một số cải tiến:
Lưu ý
Script hiện tại chỉ hoạt động với EasyEngine có website nằm ở đường dẫn /var/www
Hướng dẫn cài đặt
wget -qO rclone_backup.sh https://duonganhtuan.com/rclone && chmod +x rclone_backup.sh
SERVER_NAME
thành đường dẫn upload lên remote, chỉnh sửaMYSQL_PASSWORD
thành mật khẩu của tài khoản root MySQL, chỉnh sửaDriveremote
thành tên remote đã tạo trong Rclone../rclone_backup.sh
để chạy trực tiếp.