时间:2021-07-01 10:21:17 帮助过:38人阅读
一、mysql:
参数说明:
$user | $password | $targethost | $port | $charset | $dbname | $table | $filename |
用户名 | 密码 | ip(本地为localhost) | 端口 | 编码 | 数据库名 | 表名(仅表级备份需要) | 文件名 |
备份:mysqldump --single-transaction -l -u $user -p'$password' -h $targethost -P $port --default-character-set=$charset $dbname $table > $filename
恢复:mysql $dbname -u $user -p'$password' -h $targethost -P $port --default-character-set=$charset < $filename
二、sqlserver:
说明:sqlserver2003及以下仅支持osql,sqlserver2005及以上同时支持osql及sqlcmd,以下方法对sqlcmd及osql均通用。
参数说明:
$user | $passwrod | $instance | $dbname | $filename | $diff_filename |
用户名 | 密码 | 实例名 | 数据库名 | 全量备份文件名 | 增量备份文件名 |
全量备份:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE; ALTER DATABASE $dbname SET ONLINE"
增量备份:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE,NORECOVERY; RESTORE DATABASE $dbname FROM DISK='$diff_filename' WITH RECOVERY; ALTER DATABASE $dbname SET ONLINE"
全量恢复:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE; ALTER DATABASE $dbname SET ONLINE"
增量恢复:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE,NORECOVERY; RESTORE DATABASE $dbname FROM DIST='$diff_filename' WITH RECOVERY; ALTER DATABASE $dbname SET ONLINE"
三、oracle:
oracle的备份及恢复主要使用rman,感兴趣的可以详细去了解rman的具体使用
四、redis:
说明:redis的数据备份文件存储在配置文件中的dir+dbfilename组成的全路径文件名中;
备份:redis-cli -h targethost -p $port -a $password save
恢复:只需要将备份的文件放置原目录,重启redis即可。
五、mongo:
参数说明:
$targethost | $port | $dbname | $backup_dir | $user | $password | $table | $recovery_dir |
ip地址 | 端口 | 数据库名 | 保存路径 | 用户名 | 密码 | 表名(表级恢复) | 恢复路径 |
备份:mongodump --host $targethost:$port -d $dbname -o $backup_dir -u $user -p $password
恢复:mongorestore --host $targethost:$port -d $dbname -u $user -p$password -c $table $recovery_dir
六、postgres:
$targethost | $port | $user | $dbname | $filename | $recovery_file |
ip地址 | 端 口 | 用户名 | 数据库名 | 备份文件 | 恢复文件 |
备份:pg_dump -c -b -h $targethost -p $port -U "$user" $dbname > $filename
恢复:psql -h $targethost -p $port -U "$user" -d $dbname -f $recovery_file