croxinuz Posted April 2, 2014 Group: Members Topic Count: 27 Topics Per Day: 0.01 Content Count: 62 Reputation: 0 Joined: 03/18/12 Last Seen: May 12, 2020 Share Posted April 2, 2014 i have autobackup from sir Brian. #!/bin/bash dbhost='localhost' dbuser='ragnarok' dbpass='ragnarok' dbname='ragnarok' savepath=$(dirname $0) # OR something like '/root/backup' date=`date +%Y-%m-%d_%H%M` month=`date +%Y-%m` filename="$savepath/$month/"$dbname"_"$date".sql" if [[ ! -d "$savepath/$month" ]]; then mkdir -p "$savepath/$month" chmod 700 "$savepath/$month" fi mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpass $dbname > $filename chmod 400 $filename how to auto delete my backup if date > 3 days. i'm blind to modify this backup script sorry for my bad english >.< Quote Link to comment Share on other sites More sharing options...
Mitsu Posted April 9, 2014 Group: Members Topic Count: 0 Topics Per Day: 0 Content Count: 7 Reputation: 0 Joined: 01/05/12 Last Seen: May 11, 2017 Share Posted April 9, 2014 This should work #!/bin/bash dbhost='localhost' dbuser='ragnarok' dbpass='ragnarok' dbname='ragnarok' savepath=$(dirname $0) # OR something like '/root/backup' duration=3 # value in days date=$(date +%Y-%m-%d_%H%M) date_old=$(date +%Y-%m-%d_%H%M --date="${duration} days ago") month=$(date +%Y-%m) month_old=$(date +%Y-%m --date="${duration} days ago" ) filename=${savepath}"/"${month}"/"${dbname}"_"${date}".sql" filename_old=${savepath}"/"${month_old}"/"${dbname}"_"${date_old}".sql" if [[ ! -d "$savepath/$month" ]]; then mkdir -p "$savepath/$month" chmod 700 "$savepath/$month" fi mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpass $dbname > $filename chmod 400 $filename # removing files older than [duration] days based on filename if [[ -f "${filename_old}" ]]; then rm -f "${filename_old}" fi # clean empty folders if [ ! "$(ls -A ${savepath}{month_old})" ]; then rm -rf "${savepath}{month_old}" fi exit 0 Quote Link to comment Share on other sites More sharing options...
croxinuz Posted April 2, 2014 Group: Members Topic Count: 27 Topics Per Day: 0.01 Content Count: 62 Reputation: 0 Joined: 03/18/12 Last Seen: May 12, 2020 Author Share Posted April 2, 2014 i have searching from google,but i don't understand how to make it :s Quote Link to comment Share on other sites More sharing options...
croxinuz Posted May 3, 2014 Group: Members Topic Count: 27 Topics Per Day: 0.01 Content Count: 62 Reputation: 0 Joined: 03/18/12 Last Seen: May 12, 2020 Author Share Posted May 3, 2014 This should work #!/bin/bash dbhost='localhost' dbuser='ragnarok' dbpass='ragnarok' dbname='ragnarok' savepath=$(dirname $0) # OR something like '/root/backup' duration=3 # value in days date=$(date +%Y-%m-%d_%H%M) date_old=$(date +%Y-%m-%d_%H%M --date="${duration} days ago") month=$(date +%Y-%m) month_old=$(date +%Y-%m --date="${duration} days ago" ) filename=${savepath}"/"${month}"/"${dbname}"_"${date}".sql" filename_old=${savepath}"/"${month_old}"/"${dbname}"_"${date_old}".sql" if [[ ! -d "$savepath/$month" ]]; then mkdir -p "$savepath/$month" chmod 700 "$savepath/$month" fi mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpass $dbname > $filename chmod 400 $filename # removing files older than [duration] days based on filename if [[ -f "${filename_old}" ]]; then rm -f "${filename_old}" fi # clean empty folders if [ ! "$(ls -A ${savepath}{month_old})" ]; then rm -rf "${savepath}{month_old}" fi exit 0 thank you sir ^.^ Quote Link to comment Share on other sites More sharing options...
Question
croxinuz
i have autobackup from sir Brian.
how to auto delete my backup if date > 3 days.
i'm blind to modify this backup script
sorry for my bad english >.<
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.