How to backup mysql database every 10 minutes - mysql

I want to backup MySQL database every 10 minutes. how i can do it. I don't know how to use procedure or function for it.
I have used
mysqldump -u root -p mydatabase > mydb_backup.sql
I also want to add date and time in end of backup database name. I should only keep latest 3 backup database in system and destroy other database.

How about a backup every second? Well, actually it is "continually". It is called "Replication".
You build another mysql server (machine) as the Slave.
Then copy the data to the Slave, and do CHANGE MASTER on the Slave to have it continually replicate from the Master (which is your current instance of mysql).

AutoMySQLBackup has some great features to:
backup a single database, multiple databases, or all the databases on the server;
each database is saved in a separate file that can be compressed (with gzip or bzip2);
it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.).
or you can find more info here 10 Ways to Automatically & Manually Backup MySQL Database

If you are working in unix or linux you can use crontab for scheduling.
To add the the time and date to the backup file you can use a syntax similar to the following
mysqldump -u root -p mydatabase > mydb_backup_`date+"%Y%m%d%H%M%S"`.sql

Related

Copy files across servers in a weekly basis

I want to create a cronjob to synchronize two servers on a weekly basis. I have two servers A and B and I want to synchronize the files and mysql databases to the second server on a weekly basis. I think rsync can be used to synchronize the files. But how can I synchronize the database ?
Thanks,
I have managed to create a script that will restore the database to the remote server.
mysqldump -u username -ppassword database_name | mysql -u Username_remote -ppassword_remote --host=remote_server_IP -C databse_name >> ``date "+%Y-%m-%d".log`
This is not the best way to do this and not recommended in live servers.

MySQL backup procedure for large databases

I currently make a backup of my 2.5GB (and growing) MySQL Database every day. I have over 100 tables that are backed up.
I use this command:
mysqldump --user=user --password=pass --host=localhost db_name | gzip > backup.sql.gz
Works great but when I need to quickly restore data to a single table, it's a horrible process. I have to download the backup, extract the ZIP file, wait forever for the editor to load the SQL file so that I can remove the other tables I don't require. When I need this done fast, I'm pulling my hair out
Can anyone recommend a better way to store MySQL backups? Is there a command to split all the tables into their own sql files?
Appreciate your help!

How do I do an incremental backup for a mysql database using a .sql file?

Situation: our production mysql database makes a daily dump into a .sql file. I'd like to keep a shadow database that is relatively up to date.
I know that to create a mysql database from a .sql file, one uses:
mysql -u USERNAME -p DATABASENAME < FILE.SQL
For our db, this took 4-5 hours. Needless to say, I'd like to cut that down, and I'm wondering if there's a way to just update the db with what's new/changed. On Day 2, is there a way to just update my shadow database with the new .sql file dumped from the production db?
MySQL Replication is the way to go.
But, in cases, where that is not possible, use the following procedure:
Have a modifed timestamp column in all your tables and update this value whenever a row is inserted/changed.
Use the following mysqldump options to take the incremental SQL file (this uses REPLACE commands instead of insertcommands, since the existing record will be updated in the backup database).
Keep a timestamp value somewhere placed in the file system. and use it in the where condition. MDFD_DATE is the column name on which you need to filter. On successful backup, update the value stored in the file.
skip-tz-utc prevents MSQL from automatically adjusting the timestamp values, based on your timezone.
mysqldump --databases db1,db2 --user=user --password=password --no-create-info --no-tablespaces --replace --skip-tz-utc --lock-tables --add-locks --compact --where=MDFD_DATE>='2012-06-13 23:09:42' --log-error=dump_error.txt --result-file=result.sql
Use the new sql file and run it in your server.
Limitations:
This method will not work if some records are deleted in your database. You need to manually delete them from the backup databases. Otherwise, keep a DEL_FLAG column and update it to 'Y' in production for deleted records and use this condition to delete records in the backup databases.
This problem can be solved using mysql synchronization.
Some links to guide you:
http://www.howtoforge.com/mysql_database_replication
Free MySQL synchronization tool
https://launchpad.net/mysql-proxy
https://www.google.com.br/search?q=mysql+synchronization

How to backup my MySQL's databases on Windows Vista?

How can I backup my MySQL's databases? I'm using Windows Vista and MySQL 5.1.
I have found the folder "C:\Users\All Users\MySQL\MySQL Server 5.1\data" with all my database files and copy them, but how can I restore them if I need?
Thank you.
You could use the mysqldump tool:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
That way you'd get SQL files that you could just execute.
You can also go surf to localhost/phpmyadmin and go to 'export' and select the databases you want to export.
The backup process does not have anything to do with your operating system. Simply export your databases.
You can back up the database files directly, but this can be dangerous if the database is in active use at the time you do the backup. There's no guarantee that you'll make a consistent and valid backup if a query starts modifying on-disk data. You may end up with broken tables.
The safest route is to use mysqldump to output a set of sql statements which can recreate the database completely (table creation + data) in one go. Should you need to restore from backup, you can simply feed this dump file back to mysql:
mysqldump -p -u username nameofdatabase > backup.sql
and restore via:
mysql -p -u username nameofdatabase < backup.sql
The .sql file is just a plaintext dump of all the queries required to rebuild the table(s) and their data.

Replicate MYSQL data from stage to dev with a script

I have two versions of my application, one "stage" and one "dev."
Right now, "stage" is exposed to the real world for beta-testing.
From time to time, I want an exact replica of the data to be replicated into the "dev" database.
Both databases are on the same hosted Linux machine.
Sometimes I create "dummy" data in the development environment. At this stage, I'd be fine if it needs to get written over in stage.
Thanks.
Be sure to add security to your script so only the user you are authorizing is able to run that script. basically you want to use mysql and mysqldump commands.
mysqldump -u username --password=userpass --add-drop-database --add=locks --create-options --disable-keys --extend-insert --result-file=database.sql databasename
mysql -u username --password=userpass -e "source database.sql;"
The first command will make the backup the second command will bring the backup to another database engine. Be careful because if you run it on the same exact process of mysql you are only backing up the database adn then restoring it to the same database, you have to change the database name.
Hope this helps.
Just use mysqldump to create a backup of the staging database and then load the dump file over your dev database. This will give you an exact copy of the stage data.