Backing up a database to a file
A backup turns a database into a file. That file can be moved to another machine, kept as a safety copy or used to seed a new environment.
The command
SQL
BACKUP DATABASE Shop
TO DISK = 'C:\backups\Shop.bak'
WITH INIT;Good habits
- Back up before any change you might want to undo.
- Keep the backup somewhere other than the machine that holds the database.
- Test a restore now and then, because a backup you cannot restore is not a backup.
Note the version. A backup can be restored on the same or a newer engine, not on an older one. If you plan to move it to another machine, check the version there first.
The reverse operation is restoring a database from a backup file.