March 14,2005

用 Gmail 備份 MySQL Database

之前在 386bsd 上 post 的,整理一下放上來。


先在自己的機器與 mysql server 安裝 GnuPG (現在是 1.4.0):


# cd /usr/ports/security/gnupg
# make install clean

如果是 FreeBSD 4.x,在自己的機器上產生 key 前,先設定 random device:


# rndcontrol -s 5
# rndcontrol -s 11

其中的 5 與 11 是 IRQ number,可以用下面的指令看哪個 IRQ 可以當 random device:


# pciconf -l

接下來在自己機器上用下面的指令產生 publickey 與 privatekey:


$ gpg –gen-key


應該會有許多問題要答,分別是:


Your selection? 1 (用 DSA & Elgamal)
What keysize do you want? (2048) 4096 (最高的 4096 bits)
Key is valid for? (0) 0 (這把 key 不設 expire)
Is this correct? (y/N) y (確定不設 expire)
Real name: Gea-Suan Lin (名字)
Email address: gslin@ccca.nctu.edu.tw (e-mail)
Comment: (不用填,enter 過去)
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o (Okay)
Enter passphrase: !@#$%^ (設個密碼吧)
Repeat passphrase: !@#$%^ (同樣的密碼再打一次)

然後讓他跑一陣子 (4096 bits 比較久),這樣應該就把 key 生出來了,像:


gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 1024D/31ABE498 2005-03-12
Key fingerprint = 826E E0DF 72ED 4BEB FA85 52E3 9F02 FDC3 31AB E498
uid Gea-Suan Lin <gslin @ccca.nctu.edu.tw>
sub 4096g/69E68E46 2005-03-12

然後將這把 key export 出來:


$ gpg -a –export gslin > /tmp/publickey.gslin

然後把 publickey.gslin 拿到 mysql server 主機上 import 給 root 處理:


# gpg –import < publickey.gslin


然後設定信賴程度:


# gpg –edit-key gslin trust

接下來會問幾個問題:


Your decision? 5 (I trust ultimately)
Do you really want to set this key to ultimate trust? (y/N) y
Command> save (存進去)

把下面的內容放到 /usr/local/sbin/backup-db.sh,其中粗體的部分代表需要改的:


#!/bin/sh
DATE=`/bin/date +%Y%m%d`

/usr/local/bin/mysqldump -A -u root --password=PASSWORD | gzip -9 | uuencode mysql-${DATE}.gz | gpg -a -e -r gslin | mail -s “evil.NCTU.edu.tw MySQL backup (${DATE})” evilGMAIL@gmail.com

最後在 /etc/crontab 設定每天 03:00 備份:


0       3       *       *       *       root    /usr/local/sbin/backup-db.sh > /dev/null 2>&1



Posted by gslinn at 樂多Roodo! │03:49 │回應(0)引用(6)
工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/38949
引用列表:
Wellbutrin alcohol. Wellbutrin withdrawal.
Wellbutrin.【Wellbutrin and pregnancy.】 at July 31,2007 03:17
Black ice ephedra. Ephedra products. Twinlab ripped fuel with ephedra. Hunt on for ephedra substitutes cbs news. Ephedra.
Ephedra.【Ephedra.】 at September 4,2007 21:52
Wellbutrin and liver enzymes. Wellbutrin bleeding. Wellbutrin.
Wellbutrin.【Wellbutrin.】 at September 5,2007 06:05
How long does fioricet show up in blood work. Fioricet. Fioricet free shipping. Fioricet 120.
Fioricet.【Fioricet.】 at September 26,2007 23:21
Adderall xr. Adderall.
Adderall side effects.【Adderall.】 at November 25,2007 12:14
Ephedra products. Colorado ephedra attorney. Ephedra lawyers los angeles. Connecticut ephedra lawyers. Ephedra.
Ephedra.【Ephedra.】 at November 30,2007 22:32