BACKUP
BACKUP is a SQL statement used to create consistent copies of significant SQL Server data. The primary purpose for using the BACKUP command is to safeguard the database against potential loss or damage. This is accomplished by keeping backup copies, which can then be used to restore the database should an issue arise. Backups can be run on most components of a SQL server including, but not limited to, full databases, transaction logs, and filegroups.
Example
Output
BACKUP DATABASE successfully processed 0 pages in 120.036 seconds (0.000 MB/sec)
Explanation
In the above example code, the SQL BACKUP DATABASE
statement is used to create a full backup of YourDatabase
to a specified disk location. In this case, the path for backup is /path/to/your/directory/YourDatabase.bak
.
The output statement signifies that the backup process was successful and displays the time it took to complete the backup along with the transfer rate (in MB/sec).
Please note this syntax can vary depending upon the SQL distribution you’re using. This example is based on Microsoft SQL Server. MySQL does not support the BACKUP DATABASE
command. You may have to use mysqldump or similar tools.
Example
Output
Explanation
In the provided example, the PostgreSQL database ‘testDB’ is being backed up. The BACKUP DATABASE
command is used to create a full backup of the database. The backup file ‘testDB.bak’ is saved in the directory ‘/var/lib/postgresql/’. The output message displays the success of the operation, how many pages were processed, and the operation’s speed.
Example
Output
Explanation
The BACKUP DATABASE
command is used to create a full back up of the TestDB
database. The TO DISK
clause specifies the file path where the backup is to be stored. The WITH FORMAT
argument specifies that a new backup file should be created, overwriting any existing file. The MEDIANAME
and NAME
options are used to specify the media name and the logical name for the backup. The Output shows the successful execution of the backup command.
Example
Output
Explanation
The BACKUP DATABASE
command in Oracle is used to create a backup of the database. The FORMAT
specification is used to specify the filename format for the backup pieces. The ‘%U’ in the filename is a uniquely generated filename that ensures the filename does not clash with existing filenames, and the entire backup is placed in ‘/tmp’ directory.