Remote database backup script

Developed In: PHP — Contributed by: Mysql Tech

Remote database backup script that will backup a database in either .zip or gzip and remotely upload it to a different server via FTP or another method. Several methods are:

scp with ssh keys, rsync or even mysqldump directly. The easiest method is to create a user (backup for example) with just select as privilege and run mysqldump from cron.daily.

Don't forget to allow mysqldump to connect to server from your remote location (grant select * to bakup@'yourip' identified by 'password')


Mysql Tech
PHP
  1. #!/bin/bash
  2. BACKUP_DIR=/backup/
  3. DAY=`date +%d`
  4.  
  5. mkdir -p $BACKUP_DIR/$DAY/
  6.  
  7. mysqldump -u root -ppassword database > $BACKUP_DIR/$DAY/dump.sql
  8.  
  9. cd $BACKUP_DIR/$DAY/
  10.  
  11. gzip dump.sql
  12.  

Current Tags

You must be logged in to tag this tool

There is no locking before starting the backup. Backup will be inconsistent with this way.

很好

Votes

  • Rated 3.00 out of 5
Rated 3.00 out of 5 with 2 votes cast.
You must be logged in to vote.

Watches

0 members are watching this tool
You must be logged in to track this tool.

Provide Feedback

Please note:
HTML will be purified, but we allow for a number of HTML tags so that you have the flexibility to decorate your comment text to some extent. The comments allow the following HTML tags:

strong, b, em, blockquote, a, code, pre

To put code into your comment, simply encapsulate your code with
[code language="XXX"][/code], where XXX is any common language, for instance "PHP", "SQL", "C", etc.



You must be logged in to comment