Hits: 66

如何使用phpmyadmin自动执行数据库备份(How to automate database backup using phpmyadmin)

正解:

MYSQL
0 0 * * * /usr/local/bin/mysqldump -uLOGIN -PPORT -hHOST -pPASS DBNAME | gzip -c > /share/bak/mysql/"DBNAME"-$(date +%Y%m%d).gz
postgres  
威联通安装 postgres  https://10001blog.xslinc.com/?p=9087     群晖 postgres  https://10001blog.xslinc.com/?p=2844
/share/CACHEDEV1_DATA/.qpkg/QPostgreSQL/bin/pg_dump -U postgres -P port -h localhost -p password dbname  \
| gzip -c > /share/bak/mysql/"DBNAME"-$(date +%Y%m%d).gz
# 这个未成功
在群晖控制面板中选择文件服务,选择rsync服务;开启服务并添加rsync用户 ( 新建 rsync 用户,设置随机密码)
rsync 配置与详解    https://10001blog.xslinc.com/?p=9150
rsync -avzu --progress rsync@server:/volume1/odoo_bak/ /share/bak/odoo/ 
# 手动备份,自动备份未成功
vi /share/bak/mysql/mysql-bak  增加命令  
chmod +x mysql-bak 赋予执行权限;
crontab -e
0 0 * * * /share/bak/mysql/mysql-bak    #定期备份
30 7 * * * find /share/bak/mysql/  -type f -prune -mtime +7 -exec rm -f {} \;   # 删除7天前备份的;

/etc/init.d/crond.sh restart 重启 crontab

 

Linux自动备份MySQL数据库脚本代码    https://www.cnblogs.com/linuxnotes/p/3413593.html

#!/bin/bash
mysql_pwd="password"
mysql_dump="/usr/local/mysql/bin/mysqldump"
cur_year=$(date +"%Y") 
cur_month=$(date +"%m") 
cur_day=$(date +"%d") 
dump_path="/share/bak/mysql/"
arr_tables=( 
"table_1"
"table_2"
"table_3"
) 
if [ ! -d "$dump_path" ]; then
mkdir -p "$dump_path"
fi
for cur_table in ${arr_tables[*]}; do
$mysql_dump -uroot -p$mysql_pwd --opt mydb $cur_table | gzip > $dump_path/$cur_table.sql.gz 
done