每天自动备份MYSQL数据库(dh空间)

Getting a Backup From the ShellYou can use the mysqldump shell command to make a backup, also. This is more difficult to do the first time than the phpMyAdmin method above, but you can automate it so that the system backs up your database for you. See Automatic Backup for instructions on how to automate this.

  1. Log into your old server with SSH or Telnet
  2. Type the following command:

mysqldump –opt -uusername -ppassword -h yourMySQLHostname dbname > output.sql

  1. Log into your account with FTP and download the newly created output.sql file.

在查找“用SSH备份mysql”时,发现的——“Dreamhost下每天自动备份mysql数据库,并发送到指定邮箱”。
觉得比wordpress的一些备份plugin好,决定启用。

1、用putty登录你的dreamhost;

2、运行

<LI class=hl-firstline>cd ~
mkdir backups
mkdir backups/archives

3、新建一个名为“.sh”的文件,并输入下列代码:

<LI class=hl-firstline>#!/bin/bash
cd /home/username/backups/ #username改为你登录ssh时用的用户名
mkdirmysql
suffix=$(date +%y%m%d)
mysqldump –opt -uUser -pPass -hmysqlA.domain.comdb_nameA > mysql/db_nameA.$suffix.sql#User为数据库用户名,pass为数据库用户密码,mysqlA.domain.com为数据库地址,db_nameA为数据库名,请根据你的情况修改。
tarzcfarchives/mysql_backup.$suffix.tar.gzmysql/*
rm -rmysql/
muttyou@domain.com -a /home/username/backups/archives/mysql_backup.$suffix.tar -s“MySQL Backup“#you@domain.com修改为你准备用于收取备份压缩包的邮箱。
保存后,上传到backups文件夹中。

4、在putty中运行

<LI class=hl-firstline>dos2unix ~/backups/mysql.sh
chmod 755 ~/backups/mysql.sh

5、在Dreamhost的panel,Goodies->Cron Jobs中新建Cron任务,选项设置为
Command to run: /home/User/backups/mysql.sh
#User改为你登录SSH时用的用户名。

时间照下图设置,将在北京时间每天的24:10左右运行备份MySQL程序,并发送备份压缩包到你指定的邮箱。

open_img('attachments/200802/3734208507.jpg')

发表评论

邮箱地址不会被公开。 必填项已用*标注

click to changeSecurity Code