Advertisement

09.26.2008 at 09:53AM PDT, ID: 23766697
[x]
Attachment Details

MySQL backup script using mysqlhotcopy / gzip / incremental backups

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0
Tags:

MySQL, MySQL Server, Database backups using mysqlhotcopy

Hello,

Currently I have this shell script to backup my databases using mysqlhotcopy and saving 4 previous copies of the backup. The script is working fine and it does the work well. The Only thing I need to add is that instead of creating just the folder of the backup db, it also compress those created folders in a separate gzip files, so that way I can send it via FTP to another serve more easily than transferring all the db file contents.

So basically is change this script to instead of creating the folders like this:
testdb.1
testdb.2
testdb.3
testdb.4

it creates something like
testdb.1.tar.gz
testdb.2.tar.gz
testdb.3.tar.gz
testdb.4.tar.gz

and so on....

That's basically it...

Attached is the code...

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
#!/bin/sh
 
# List of databases to be backed up separated by space
dblist="testdb testdb2 testdb3"
 
# Directory for backups
backupdir=/home/mysql/backup
 
# Number of versions to keep
numversions=4
 
# Full path for MySQL hotcopy command
hotcopycmd=/usr/bin/mysqlhotcopy
 
# MySQL Username and password
userpassword=" --user=root --password=password"
 
# Create directory if needed
mkdir -p ${backupdir}
if [ ! -d ${backupdir} ] 
then
	echo "Invalid directory: ${backupdir}"
exit 1
fi
 
# Hotcopy begins here
echo "Hotcopying MySQL Databases..."
RC=0
for database in $dblist
do
	echo "Hotcopying $database ..."
	$hotcopycmd $userpassword $database ${backupdir}
	RC=$?
	if [ $RC -gt 0 ]
	then
		break;
	fi
 
	# Rollover the backup directories
	i=$numversions
	mv ${backupdir}/${database} ${backupdir}/${database}.0 2> /dev/null
	rm -fr ${backupdir}/${database}.$i 2> /dev/null
	while [ $i -gt 0 ]
	do
		 mv ${backupdir}/${database}.`expr $i - 1` ${backupdir}/${database}.$i 2> /dev/null
		 i=`expr $i - 1`
	done
done
 
if [ $RC -gt 0 ]
then
	echo "MySQL Hotcopy failed!"
	exit $RC 
else
	# Hotcopy is complete. List the backup versions!
	ls -l ${backupdir}
	echo "MySQL Hotcopy is complete!"
fi
exit 0
Answered By: MikeOM_DBA
Expert Since: 07/01/2002
Accepted Solutions: 948
Computer Expertise: Guru
MikeOM_DBA has been an Expert for 6 years 6 months, during which he has posted 3088 comments and answered 948 questions. MikeOM_DBA is just one of 2167 experts in the MySQL Server Zone. 1 expert collaborated on this answer, which was graded an "A" by the asker.
 
 
 
 
20081119-EE-VQP-47 / EE_QW_2_20070628