2014年5月8日 星期四

[Linux] Start-up a VirtualBox VM ; Synchronize Two MySQL Databases ; Crontab Schedule MySQL Database Backup

To list out all the running VMs:
VBoxManage list runningvms

To start-up a virtualBox VM:
VBoxManage startvm {The VM Name, e.g. CateringSys, Case-sensitive} --type headless
The correct response:
Waiting for VM "{The VM Name}" to power on...
VM "{The VM Name}" has been successfully started

To Synchronize Two MySQL Databases
(Override A with B - Override (database to be updated) with (The most updated database) )

On the most updated server(B), run the following command:
mysqldump -u {The MySQL username} --password={The password} {The database name} | mysql -u {The remote MySQL's username} --password={The remote MySQL's password} --host={The remote host's IP, e.g. 192.168.1.40 or external IP} {The remote database name}
So as to synchronize data to the remote server (A).

Schedule database backup:
crontab -e

# Inside the crontab file
# * Output a .sql backup file
# Say, do the following at 3:00 a.m. daily
# Note that slash is needed for escaping character '%', and ':' in the file name is prohibited
0 3 * * * mysqldump -u {The MySQL username} --password={The password} {The database name} > {The directory path for storing the backup .sql file, e.g. [/home/me/mysql_backup/]}{file name, e.g. [mysql_backup_`data +\%Y=\%m-\%d_\%H=\%M-\%S`.sql]} 2>&1 

# * Synchronize to the other database
# Say, do the following at 4:00 p.m. daily
0 16 * * *  mysqldump -u {The MySQL username} --password={The password} {The database name} | mysql -u {The remote MySQL's username} --password={The remote MySQL's password} --host={The remote host's IP, e.g. 192.168.1.40 or external IP} {The remote database name} 2>&1

Save the file. Done.

For more details about crontab, please read http://linux.vbird.org/linux_basic/0430cron.php .

沒有留言:

張貼留言

[康復路] 試完又試

見了醫生,因為血色素又變低了,醫生想檢查是否「缺鐵」為成因,檢查又檢查…… 感覺有些麻煩……又抽血,又要留樣本…… 令我回想起當日入院的時光,因為一些原因,留樣本只需留一次,免卻留三次的麻煩;現在每天都要留一次,連續三天。每天早上就要跑醫院一趟再上班。 幸好也完成了。 第二次抽血...