commit 86e50ca1eb585b4283921021cadcede6091d6c62 Author: panda Date: Tue Mar 17 19:35:35 2020 +0100 first commit diff --git a/mysql_backup_split.sh b/mysql_backup_split.sh new file mode 100644 index 0000000..a56758c --- /dev/null +++ b/mysql_backup_split.sh @@ -0,0 +1,19 @@ +timenow=$(date \+\%Y\%m\%d) + +#common variables: +retention_days="31" #after this value your dumps will be automatically pruned +basedir="/mnt/backup/_MYSQLDUMP/" #leave a trailing "/" . basedirectory where you will save the backups, the folders up to mysql_basedir must be manually created + +#specific variables: +mysql_basedir="MYSQL_PRD/" #leave a trailing "/" . directory where your backup will be saved (in $basedir) +mysql_host="CHANGEME" #your mysql/mariadb db host +mysql_user="bck_user" #your mysql/mariadb READONLY user +mysql_pass="CHANGEME" #your mysql/mariadb READONLY user pass +mysql_suff="CHANGEME_" #leave a trailing unserscore. suffix for the folder that will be created like this: /basedir/mysql_basedir/mysql_suff_timenow +mysql_dir=$basedir$mysql_basedir$mysql_suff$timenow + +mkdir $mysql_dir +cd $mysql_dir +mysql -h $mysql_host -u $mysql_user -p$mysql_pass -N -e 'show databases' | while read dbname; do mysqldump -h $mysql_host -u $mysql_user -p$mysql_pass --compress "$dbname" | gzip -c > "$dbname".sql.gz; done + +find $basedir$mysql_basedir -type d -mtime +$retention_days -name $mysql_suff* -exec rm -rf {} \;