Linux批量备份导出mysql数据库和批量打包备份网站文件
批量备份导出mysql数据库脚本
#!bin/sh
if [ ! -n "$1" ]; then
echo "www root path required."
exit 1
fi
# backup sub folders
dirList=$(ls -p $1 | grep / | tr -d /)
for dir in $dirList; do
tar cvzf $dir.tar.gz $1/$dir
done
批量打包备份网站文件脚本
#!/bin/bash
if [ ! -n "$1" ]; then
echo "DB host required."
exit 1
fi
if [ ! -n "$2" ]; then
echo "DB port required."
exit 1
fi
if [ ! -n "$3" ]; then
echo "DB user required."
exit 1
fi
if [ ! -n "$4" ]; then
echo "DB password required."
exit 1
fi
dbhost=$1
dbport=$2
dbuser=$3
dbpass=$4
for db in $(mysql -u$dbuser -p$dbpass -P$dbport -h$dbhost -e "show databases"); do
echo $db
mysqldump -u$dbuser -p$dbpass -P$dbport -h$dbhost --events --single-transaction --master-data=2 $db >$db.sql
tar cvzf $db.tar.gz $db.sql
rm -rf $db.sql
done
评论