hikashin-rae Posted April 25, 2017 Group: Members Topic Count: 18 Topics Per Day: 0.00 Content Count: 213 Reputation: 24 Joined: 01/14/13 Last Seen: Yesterday at 08:40 PM Share Posted April 25, 2017 Hello guys, Anyone have a script of automatic backup for server every 1 week? or per day? Im using debian. Thank you. Quote Link to comment Share on other sites More sharing options...
0 Jey Posted April 25, 2017 Group: Members Topic Count: 5 Topics Per Day: 0.00 Content Count: 249 Reputation: 73 Joined: 10/20/12 Last Seen: August 16, 2018 Share Posted April 25, 2017 #!/bin/bash usr="backup" pw="yoursqldbpassword" pw7z="your7zpassword" dbs=(rathena board website) date=$(date -I) for db in "${dbs[@]}" do filename="${db}/${db}_${date}.sql" echo "Dumping Database: $db ..." mysqldump -u $usr -p$pw $db > $filename # creates a sql dump tar cf - $filename | 7za a -si -p$pw7z ${filename}.tar.7z # compresses the dump # ncftpput -Vmu [email protected] -p ftp ftp.host.com / ${filename}.tar.7z # copy it to an ftp server rm $filename done I'm using something like this. I'd recommend to add an explicit database user for backups with read access only. And using 7zip is good for both compression and encryption of the data. To run it on a daily basis I'd recommend using a cronjob: 30 5 1 * * cd ~/backup && ./backup_full.sh > /dev/null 2>&1 30 5 2-31 * * cd ~/backup && ./backup.sh > /dev/null 2>&1 Mine is split into two parts. backup.sh is the above script and dumps everything except the log database. It runs every day except the first day of the month. backup_full.sh also includes the log table and is run only once every month. dbs=(rathena rathena_log board website) # dbs entry in full_backup.sh Keep in mind: A backup on the same host will not help you at all if the hard drive is broken. I'm also interested in other solutions, so keep on posting them 1 Quote Link to comment Share on other sites More sharing options...
0 Akkarin Posted April 25, 2017 Group: Forum Manager Topic Count: 282 Topics Per Day: 0.06 Content Count: 3144 Reputation: 1630 Joined: 03/26/12 Last Seen: April 15 Share Posted April 25, 2017 I use the following to grab both SQL and File based backups: #!/bin/bash dbhost='127.0.0.1' dbuser='user' dbpass='pass' dbname='db' savepath='/home/backups' date=`date +%Y-%m-%d_%H%M` month=`date +%Y-%m` filename="$savepath/$month/"$dbname"_"$date".sql" tarname="$savepath/$month/"$dbname"_"$date".tar.gz" 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 dirname='/var/www/htdocs' tar -cvpzf $tarname $dirname chmod 400 $tarname This is ideal for when you also have file based logs (like with FluxCP) so everything is backed up and saved to a location. I have another script running on a separate vps that remotes to the server that has the new backups and copies them. This script doesn't send them anywhere. 1 Quote Link to comment Share on other sites More sharing options...
0 hikashin-rae Posted April 26, 2017 Group: Members Topic Count: 18 Topics Per Day: 0.00 Content Count: 213 Reputation: 24 Joined: 01/14/13 Last Seen: Yesterday at 08:40 PM Author Share Posted April 26, 2017 Thanks both of you :). i really appreciate it! Quote Link to comment Share on other sites More sharing options...
0 Habilis Posted April 26, 2017 Group: Members Topic Count: 4 Topics Per Day: 0.00 Content Count: 31 Reputation: 14 Joined: 06/13/16 Last Seen: October 28, 2018 Share Posted April 26, 2017 Here is what I use https://habilisbest.com/sql-database-automatic-backups Quote Link to comment Share on other sites More sharing options...
0 hikashin-rae Posted April 27, 2017 Group: Members Topic Count: 18 Topics Per Day: 0.00 Content Count: 213 Reputation: 24 Joined: 01/14/13 Last Seen: Yesterday at 08:40 PM Author Share Posted April 27, 2017 On 4/26/2017 at 10:35 PM, Habilis said: Here is what I use https://habilisbest.com/sql-database-automatic-backups Thank you i really appreciate it Quote Link to comment Share on other sites More sharing options...
0 Habilis Posted May 5, 2017 Group: Members Topic Count: 4 Topics Per Day: 0.00 Content Count: 31 Reputation: 14 Joined: 06/13/16 Last Seen: October 28, 2018 Share Posted May 5, 2017 I improved a bit my version Quote Link to comment Share on other sites More sharing options...
Question
hikashin-rae
Hello guys,
Anyone have a script of automatic backup for server every 1 week? or per day?
Im using debian.
Thank you.
Link to comment
Share on other sites
6 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.