The loss of the database causes a lot of losses, so I wrote a script for backing up the Mysql database in Linux. It was initially in the php version, later, I found that the PHP configuration on the server restricted the calling of system functions, so I wrote another shell version. It seems that shell is really obscure, a bit like the classical Chinese in programming language. In short, it can be used. do not consider anything else.
SHELL version:
#! /Bin/bash
Db_user = "root" # database username
Db_pwd = "123456" # Database Password
Target_dir = "/home/jony/database_bakup/" # Backup Directory
Dbs = "product_db forum_db blog_db sns_db" # databases to be backed up, separated by Spaces
# Here is the cyclic backup
For db in $ dbs; do
Mysqldump-u $ db_user-p $ db_pwd $ db | gzip >$ {target_dir }$ {db }_$ (date + % F) ". SQL .gz"
Done
I don't want to talk about shell syntax anymore. I have tried it many times and I'm not used to it.
If there are no restrictions on the server, www.bkjia.com is not as comfortable as other languages, such as python and php.
PHP version:
<? Php
$ Db_user = "root ";
$ Db_pwd = "123456 ";
$ Date = date ("Ymd ");
$ Target_dir = "/home/jony/database_bakup /";
$ Db_array = array ("mysql", "phpmyadmin ");
Foreach ($ db_array as $ db_name ){
$ Command = "mysqldump-u ". $ db_user. "-p ". $ db_pwd. "". $ db_name. "| gzip> ". $ target_dir. $ db_name. "_". $ date. ". SQL .gz ";
System ($ command );
}
?>
Record it. Maybe you can use it too.