Page 1 of 1
Automaticaly Backup Database
Posted: Tue Nov 23, 2010 11:29 am
by amplifire
Hello everyone!!
I want to refer for this problem. I want to backup my database after particular interval of time. Please guide me on concept of how to do this. I have something going on in mind but still need some advice!!
Suggestions Appreciated.
Regards!!
Re: Automaticaly Backup Database
Posted: Tue Nov 23, 2010 12:07 pm
by AbraCadaver
amplifire wrote:Hello everyone!!
I want to refer for this problem. I want to backup my database after particular interval of time. Please guide me on concept of how to do this. I have something going on in mind but still need some advice!!
Suggestions Appreciated.
Regards!!
Assuming mysql, put mysqldump in a cron job.
Re: Automaticaly Backup Database
Posted: Tue Nov 23, 2010 12:34 pm
by califdon
As an alternative strategy, and in case your database is hosted somewhere that you don't have access to system functions like cron, here's another possibility to consider:
What many people don't think about, with respect to database backups, is that no purpose is served by backing up data that hasn't been modified since the previous backup, so if you design your application so that every transaction resets a timestamp in a table, then each time your application starts, it can compare the stored timestamp with the current date-time, and if more than a certain time has passed since the most recent transaction was processed, you can initiate the mysqldump, or similar function if it is not MySQL. This approach has limitations, of course. If the database is very active (transactions almost continuously) or if the database is extremely large (many gigabytes), this approach might cause slowdowns or interruptions. But for smaller and less active databases, I would prefer this to forcing backups that only replace the same data.
Re: Automaticaly Backup Database
Posted: Fri Nov 26, 2010 8:35 am
by amplifire
Yes my Database is updated regularly. New entries are made every day. I read somewhere i can use system() function and then mysqldump to backup after some times. Although time stamp is not required but i will try to use it too.
Can Anyone tell me how system() function works?
Thanx!
Re: Automaticaly Backup Database
Posted: Fri Nov 26, 2010 1:30 pm
by califdon
Re: Automaticaly Backup Database
Posted: Sun Dec 05, 2010 7:10 pm
by boyter
Code: Select all
#!/bin/sh
date=`date -I`
for I in $(mysql -u root -pPASSWORD -e 'show databases' -s --skip-column-names);
do
mysqldump -u root -pPASSWORD $I | gzip > "$date-$I.sql.gz";
done
The above is what I use. It queries for every database in the system and then dumps them into a seperate gzipped file. Works well.
Re: Automaticaly Backup Database
Posted: Fri Dec 24, 2010 12:01 am
by amplifire
Hello everyone
I referred to you for database backup using mysqldump ans system() function to execute it.
So far iam able to create backup file, but my backup file is empty. When i use mysqldump from command line, it works.
But from php it doesnt work what could be the problem?
Here's my code:
Code: Select all
if($_POST['backup'])
{
$command="mysqldump -h localhost -u root nigamkota > database/backup.sql";
system($command);
echo "<script>alert('table has been copied');</script>";
}
Regards