Home Database Mysql Tutorial mysql,sqlsever,oracle,redis,mongo,postgres等数据库备份及恢复指令整理_MySQL

mysql,sqlsever,oracle,redis,mongo,postgres等数据库备份及恢复指令整理_MySQL

Jun 01, 2016 pm 12:59 PM
backup instruction database

下列仅整理给出各个数据库备份及恢复最简单的用法,更多详细的参数及配置请查阅相关资料

一、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

二、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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

How does Go language implement the addition, deletion, modification and query operations of the database?

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

How to use MySQL backup and restore in PHP?

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

How does Hibernate implement polymorphic mapping?

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

Explore the infinite possibilities of the input method that comes with MC commands (an innovative tool to create a perfect gaming experience - the input method that comes with MC commands) Explore the infinite possibilities of the input method that comes with MC commands (an innovative tool to create a perfect gaming experience - the input method that comes with MC commands) May 02, 2024 pm 03:01 PM

Explore the infinite possibilities of the input method that comes with MC commands (an innovative tool to create a perfect gaming experience - the input method that comes with MC commands)

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

An in-depth analysis of how HTML reads the database

Analysis of the basic principles of MySQL database management system Analysis of the basic principles of MySQL database management system Mar 25, 2024 pm 12:42 PM

Analysis of the basic principles of MySQL database management system

See all articles