backup mysql database
i was doing my script..i think that it was all correct but seems that an error when was trying running the script saying bash: bla..bla.:command not found.
Code:
#!/bin/sh |
It would help if you told us which cmd it complained about ie show the 'exact' error msg.
Anyway, this line FILE= mysql-$db.$NOW I'd change to FILE=mysql-${db}.$NOW note the removal of leading space, that is wrong for bash assignments, also, disambiguation of $db var when interpolated. To check exactly what's happening, insert this at the top of your script: set -xv |
still got an error..
Code:
for db in $DBS |
A quicker way, and less scripting to backup mysql is to backup the mysql folder that contains the databases, depending on which distro you are using, it may be under /var/lib/mysql, something like this will work fine.
Code:
#!/bin/sh Code:
cd / && tar -zxf mysql-backup.tar.gz |
Quote:
With mysqldump, you can lock the tables during the dump. As for the error, try putting back ticks around the Variables that actually run commands. Try this: Code:
#!/bin/sh |
The way I backup MySQL databases is to set up replication (this can even be done on the same machine), stop the slave, backup the slave, then restart the slave. I use tar to backup the data directory.
HTH Forrest |
Here is a function i wrote to backup a postgres and mysql database to a NFS server.
Code:
exec_backupdb () |
Hello nawuza:
Here are the two files I use to backup mysql server. The first one, dblist.sh goes into the database server and list all the databases there. Then the second one takes the output of dblist.sh and backups the databases listed by dblist.sh Just run dblist.sh first, and then dbbackups.sh Call this file: dblist.sh #!/bin/bash DBPASS='mysqlpassword' SQL='show databases;' echo $SQL | mysql -u root --pass=$DBPASS > /opt/backup/192.168.1.123/full-backups/db-list.txt Call this file: db-backups.sh #!/bin/bash # Set a value that we can use for a datestamp DATE=`date +%Y-%m-%d` # Our Base backup directory BASEBACKUP="/opt/backup/192.168.1.123/full-backups/databases" DBPASS="mysqlpassowrd" for DATABASE in `cat /opt/backup/192.168.1.123/full-backups/db-list.txt` do # This is where we throw our backups. FILEDIR="$BASEBACKUP/$DATABASE" # Test to see if our backup directory exists. # If not, create it. if [ ! -d $FILEDIR ] then mkdir -p $FILEDIR fi echo -n "Exporting database: $DATABASE" /usr/bin/mysqldump --user=root --pass=$DBPASS --opt $DATABASE > $FILEDIR/$DATABASE-$DATE.sql tar cvzpf $FILEDIR/$DATABASE-$DATE.sql.tar.gz $FILEDIR/$DATABASE-$DATE.sql rm -f $FILEDIR/$DATABASE-$DATE.sql echo " ......[ Done ] " done cp -p /etc/my.cnf $BASEBACKUP I hope this helps. Thanks. --Willie |
I would use --password='your-password' on the mysqldump line. On my system -p leads to request from the shell to enter a password.
Linux Archive |
Quote:
|
thanks a lot you guys...i will try each and every solution that you all write.
|
Quote:
|
my idea to back up mysql database is like this.i just want to play it around in my local only.
1-i tar the mysql folder in the var/lib/mysql,the name of the tar is todays date. 2-i move the tar file into the my site in http://localhost/backup 3-then my other linux machine which have other script that wget http://localhost/backup/today.tgz how do i know the file that the other machine download completely the tar file.how do i checked it?!sorry if my explanation are not easy to understand. |
Quote:
As for checking if the other machine is done, well, you'll probably have to write a script to check and see if there is a process that is moving the file, or copying, however it's being run or copied over. |
Ok..shutdown the mysql service before backup it.
can you give me a guide on how to check whether the file is download completely?!for example the during the transferring tar file somehow occur a problem. how do it face the problem?! |
All times are GMT -5. The time now is 07:03 PM. |