Backup Sites and DBs

A maintenance script that will dump all your sites and databases every day into a backup folder.

  • Language: PHP
  • Released: May 3, 2011
    Last Update: May 3, 2011

Not all hosting services provide scheduled backup features, so this small tool is perfect to protect your sites in that case. Place it on hosting and change default settings on your one

define('DUMPS_PATH', 'PATH TO DUMP FOLDER');
define('ROOT_PATH',   'PATH TO ROOT SITES FOLDER');
$folders = array(
        'SITE FOLDER 1',
        'SITE FOLDER 2'
);
define('DB_HOST', 'HOSTING DB HOST');
define('DB_USER', 'HOSTING DB USER');
define('DB_PASS', 'HOSTING DB PASSWORD');

And you will get script that will perform the following actions daily:

  • Exports all DBs (allowed for DB_USER, so you can create special db-user and share all dbs with him)
  • Exports all CHANGED folders in the $folders list from ROOT_PATH
  • Gzips all data and save it in DUMPS_PATH
You need to log-in or create an account
  • Create an account
  • Log-in
Please use your real name.
Activation link will be sent to this address.
Minimum 8 characters
Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

X

Save your watchlist

Fill your details below to receive project updates from your watch list - including new versions, price changes and discounts.

I agree to the terms of use and privacy policy.

or Get a quote

for customization or integration services

  • hihi they asked me review for my old snippet - today i would code it differently, but it works great as it is
    KZ Ksu Zhytomirsky
    3 weeks ago, 0 comments
    Was this helpful?
    Flag
  • Very easy to use, gets the job done.
    NP Nathan Poultney
    3 years ago, 0 comments
    Was this helpful?
    Flag
  • Awesome component, would definitely reccommend.
    B Braunson
    3 years ago, 0 comments
    Was this helpful?
    Flag
Post a comment

Or enter your name and Email
  • M Momin 3 weeks ago
    is it possible to backup particular database and its respective subdomain? plz reply... i m working on that module so? Plz
    • Ksu Zhytomirsky Developer 3 weeks ago
      define('ROOT_PATH', '/data2/deploy/'); $folders = array( 'my_only_folder' ); this is one folder setting... for one database - change db listing to only one db /* $result = mysql_list_dbs($conn); $dbs = array(); while($row = mysql_fetch_row( $result )) { if ($row[0] == 'information_schema') continue; $dbs[] = $row[0]; } */ $dbs = array('my only database name');
    • Ksu Zhytomirsky Developer 3 weeks ago
      <?php define('DUMPS_PATH', 'PATH TO DUMP FOLDER'); define('ONE_SITE_PATH', 'FULL PATH TO ROOT SITE FOLDER'); define('DB_HOST', 'HOSTING DB HOST'); define('DB_USER', 'HOSTING DB USER'); define('DB_PASS', 'HOSTING DB PASSWORD'); define('ONE_DB_NAME', 'HOSTING DB NAME'); $big_dump_file = DUMPS_PATH . date('Y-m-d') . '.all.tgz'; $dump = DUMPS_PATH . date('Y-m-d') . '/'; if (!file_exists($big_dump_file)) { if (!is_dir($dump)) { mkdir($dump); } $db_file = $dump . ONE_DB_NAME . '.sql'; if (!file_exists($db_file) || (time() - filemtime($db_file) > 6000)) { $command = 'mysqldump -u ' . DB_USER . ' -p' . DB_PASS . ' ' . ONE_DB_NAME . ' > ' . $db_file; echo 'mysqldump ' . ONE_DB_NAME . '<br/>'; exec($command); } $dump_file = $dump . '.site.tgz'; $tmp_file = $dump . '.site.tmp'; if (!file_exists($tmp_file) || (time() - filemtime($tmp_file) > 6000)) { unlink($tmp_file); $command = ' find ' . ONE_SITE_PATH . ' -mtime -1 >> ' . $tmp_file; echo 'find ' . ONE_SITE_PATH . '<br/>'; exec($command); $modified = file_get_contents($tmp_file); if ($modified) { if ( strpos($modified, '.php') || strpos($modified, '.ctp') || strpos($modified, '.html') || strpos($modified, '.css') || strpos($modified, '.js') || strpos($modified, '.jpeg') || strpos($modified, '.jpg') || strpos($modified, '.gif') | strpos($modified, '.png') ) { $command = 'tar -cvzpf ' . $dump_file . ' ' . ONE_SITE_PATH; echo 'tar ' . $folder . '<br/>'; exec($command); } } } $command = 'tar -cvzpf ' . $big_dump_file . ' ' . $dump; echo 'gzip all<br/>'; exec($command); foreach ($folders AS $folder) { $tmp_file = $dump . $folder . '.tmp'; unlink($tmp_file); } } //this remove old dumps $date = date('Y-m-d', strtotime('-2 days')); $prev_dump_file = DUMPS_PATH . $date . '.all.tgz'; $prev_dump = DUMPS_PATH . $date . '/'; if (file_exists($prev_dump)) { $d = dir($prev_dump); while($entry = $d->read()) { if ($entry!= "." && $entry!= "..") { unlink($prev_dump . $entry); } } $d->close(); rmdir($prev_dump); } if (file_exists($prev_dump_file)) { unlink($prev_dump_file); } echo 'OK!';
    • M Momin 3 weeks ago
      thanking you..hope the problem will solve... :)
  • M Momin 3 weeks ago
    can you provide a basic example for customizing code mentioned above with some dummy url or path....? I am little bit confused so..