From b6da0d6f979654e27e111e2120ee3d189f6387d4 Mon Sep 17 00:00:00 2001 From: Xiufeng Guo Date: Wed, 12 Jun 2024 03:58:14 +0900 Subject: [PATCH] Update backup.sh Use `mariadb-dump` instead of `mysqldump`. Purge old backups for more than 7 days. --- backup.sh | 10 ++++++---- debian.sh | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/backup.sh b/backup.sh index 544485c..9c87055 100644 --- a/backup.sh +++ b/backup.sh @@ -11,7 +11,7 @@ backup_script=$(dirname "$realpath $0") rclone_config_name="" rclone_config_pass="" s3_bucket_name="" -backup_folder_name="$(date +"%Y_%m_%d_%I_%M_%p")" +backup_folder_name="$(date +"%Y_%m_%d")" # Website and Database website_folder="" @@ -26,8 +26,7 @@ rm /opt/backup/website-* # Generating a database dump backup # if $database_name exists, then dump the database, else skip if [ -n "$database_name" ]; then - mysqldump -u root $database_name > dbbackup-$backup_folder_name.sql - tar -zcvf dbbackup-$backup_folder_name.tar.gz dbbackup-$backup_folder_name.sql + mariadb-dump -u root $database_name | gzip -c > dbbackup-$backup_folder_name.sql.gz fi # if $website_folder_exclude exists, then tar the website folder excluding the $website_folder_exclude @@ -47,4 +46,7 @@ if [ -n "$database_name" ]; then rclone copy /opt/backup/dbbackup-$backup_folder_name.tar.gz $rclone_config_name:$s3_bucket_name/$backup_folder_name fi -rclone copy /opt/backup/website-$backup_folder_name.tar.gz $rclone_config_name:$s3_bucket_name/$backup_folder_name \ No newline at end of file +rclone copy /opt/backup/website-$backup_folder_name.tar.gz $rclone_config_name:$s3_bucket_name/$backup_folder_name + +# Purge old backups for more than 7 days +rclone purge $rclone_config_name:$s3_bucket_name/$(date -d "7 days ago" "+%Y_%m_%d") \ No newline at end of file diff --git a/debian.sh b/debian.sh index e143bc1..0d90375 100644 --- a/debian.sh +++ b/debian.sh @@ -469,11 +469,11 @@ function add_update_sh() { printf "\E[0m" cat > /root/update.sh << EOF #!/bin/bash -apt-get update -apt-get upgrade -y -apt-get dist-upgrade -y -apt-get autoclean -apt-get autoremove -y +apt update +apt upgrade -y +apt dist-upgrade -y +apt autoclean +apt autoremove -y EOF chmod +x /root/update.sh /root/update.sh