VPS侦探论坛

 找回密码
 注册
查看: 4711|回复: 2

要是军哥在加一个自动备份网站数据和数据库的命令脚本就更完美了? 求指导

[复制链接]
发表于 2013-7-9 19:38:17 | 显示全部楼层 |阅读模式

要是军哥在加一个自动备份网站数据和数据库的命令脚本就更完美了? 求指导
给个思路和例举一下备份用到的几种方式.

天天手工备份很累.
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-7-10 14:03:09 | 显示全部楼层


我自己在用的,挺好的,加入crontab,每天三次可以备份多个数据库
三十天自动删除老的,信息自己修改吧。




#!/bin/sh
# mysql_backup.sh: backup mysql databases and keep newest 5 days backup.
# -----------------------------
db_user="root"
db_passwd="000000"
db_host="localhost"

# the directory for story your backup file.
backup_dir="/root/mysql_backup"

# date format for backup file (dd-mm-yyyy)
time="$(date +"%Y-%m-%d-%H:%M:%S")"

# mysql, mysqldump and some other bin's path
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
MKDIR="$(which mkdir)"
RM="$(which rm)"
MV="$(which mv)"
GZIP="$(which gzip)"

#针对不同系统,如果环境变量都有。可以去掉

# check the directory for store backup is writeable
test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0

# the directory for story the newest backup
test ! -d "$backup_dir" && $MKDIR "$backup_dir"

# get all databases 设置数据库名

for db in abc cba
do
        $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd -e $db | $GZIP -9 > "$backup_dir/$time.$db.gz"
done

#delete the oldest backup 30 days ago
find $backup_dir -name "*.gz" -mtime +30 |xargs rm -rf

exit 0;
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2013-7-10 20:54:05 | 显示全部楼层

本来就写过,vpser.net 上搜一下
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 19:18 , Processed in 0.025968 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表