Mid From PDF SQL SQL & Databases

How do you restore a database from a backup?

SQL Server:

To restore a full backup in SQL Server:

  • - Full Restore
RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak';
  • - Transaction Log Restore
RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn';

To restore a database to a specific point in time (using point-in-time recovery), you would

restore the full backup and apply transaction logs.

RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backups\MyDatabase.bak';

RESTORE LOG MyDatabase FROM DISK = 'C:\Backups\MyDatabase_log.trn'

WITH STOPAT = '2023-09-14T15:30:00'; -- Restore to a specific time

PostgreSQL:

To restore a backup from a pg_dump:

  • - Full Restore from SQL dump

psql -U username -d mydatabase < /path/to/backup/mydatabase.sql

For binary dump (pg_dump -Fc):

pg_restore -U username -d mydatabase /path/to/backup/mydatabase.dump

MySQL:

To restore a MySQL database:

  • - Full Restore from SQL dump

mysql -u username -p mydatabase < /path/to/backup/mydatabase.sql

For restoring binary logs:

mysqlbinlog /path/to/binlog/mysql-bin.000001 | mysql -u username -p

More from SQL Server Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details