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

评论

Popular Posts

eXtplorer - 一个基于PHP和JavaScript的在线文件管理器

随身WiFi折腾指南: 解锁、刷机与DIY

mihomo各平台客户端下载(windows, android, macos)

常用的国内外延迟测速链接(generate_204)

十二国记 (2002)

优化PC端B站(Bilibili)免登录观看体验

Cromite - 极度注重隐私的Chromium浏览器

Win10和Win11家庭版开启远程桌面功能RDP

WinRAR 7.13 官方简体中文无广告版