RRR database backup » History » Version 1

Daniele Barchiesi, 2013-11-19 05:34 PM

1 1 Daniele Barchiesi
h1. RRR database backup
2 1 Daniele Barchiesi
3 1 Daniele Barchiesi
The RRR database that is located on paio is backed up using mysqldump from gallah. To this aim, access to the database was granted following the instructions on this tutorial 
4 1 Daniele Barchiesi
5 1 Daniele Barchiesi
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
6 1 Daniele Barchiesi
7 1 Daniele Barchiesi
h2. Perl script used to backup RRR database on paio from gallah
8 1 Daniele Barchiesi
9 1 Daniele Barchiesi
* This script is on gallah in /usr/local/backup, and has been added to /etc/cron.daily so it runs every day.
10 1 Daniele Barchiesi
* It is run by the user mysql on gallah, and it saves daily dumps at /usr/local/backup/paio
11 1 Daniele Barchiesi
12 1 Daniele Barchiesi
<pre>
13 1 Daniele Barchiesi
#!/usr/bin/perl
14 1 Daniele Barchiesi
15 1 Daniele Barchiesi
# keep 7 days worth of mysqldump.
16 1 Daniele Barchiesi
# a tape based snapshot of the structure of this may not
17 1 Daniele Barchiesi
# be reliable. TK
18 1 Daniele Barchiesi
19 1 Daniele Barchiesi
my $date=`/bin/date "+%Y%m%d"`;chomp($date);
20 1 Daniele Barchiesi
my $deldate=`date --date="7 days ago" "+%Y%m%d"`;chomp($deldate);
21 1 Daniele Barchiesi
my $x;
22 1 Daniele Barchiesi
#indicate database user and password on the following line
23 1 Daniele Barchiesi
my $mydump = "/usr/bin/mysqldump -A -R  --user= *** --password= *** --host=192.168.122.70";
24 1 Daniele Barchiesi
my $mytar  = "/bin/tar -chjf";
25 1 Daniele Barchiesi
my $compress = "/bin/gzip -9 ";
26 1 Daniele Barchiesi
27 1 Daniele Barchiesi
$x="$mydump | $compress > /usr/local/backup/paio/$date-mysql.gz";
28 1 Daniele Barchiesi
system($x);
29 1 Daniele Barchiesi
30 1 Daniele Barchiesi
unlink "/usr/local/backup/$host/$deldate-mysql.gz";
31 1 Daniele Barchiesi
</pre>