You get a backup database back by restoring it into a database server, not by opening the backup file where it sits. The exact procedure depends on what you hold — a native dump from MySQL or PostgreSQL, a SQL Server .bak, a physical file copy, or a VM snapshot — and on whether the backup was ever verified. If the backup is a logical dump and the original server is gone, you usually need a working server instance of the same database engine first, then a single import command. If the backup is corrupt or was never tested, no restore command will save it, which is why verification is discussed separately below.
The rest of this guide walks through identification, the restore itself for the four most common engines, point-in-time recovery, the mistakes that quietly destroy good backups, and the point at which you should stop and call in a professional.
Identify the backup format before you touch anything
Restoring with the wrong tool is the most common way to turn a recoverable backup into a broken one. Open the file in a text editor or run a quick inspection command before you plan the restore.
A MySQL or MariaDB logical dump is plain text and typically starts with comment lines and CREATE TABLE statements, or contains binary INSERT blocks if --hex-blob was used. A PostgreSQL custom dump is binary and begins with the bytes PGDMP. A plain SQL dump is readable text. A SQL Server backup is binary with a header block; RESTORE HEADERONLY reads it without touching the data. A SQLite backup is either a copy of a .db/.sqlite file or a .dump text file. A physical backup is a directory of data files, often accompanied by a manifest from a tool like Percona XtraBackup or pgBackRest. Snapshots are opaque to file tools and must be restored through the storage platform.
Write down the engine, its major version, the character set, and the date the backup was taken. Those four facts determine which server you need and whether the restore will succeed at all.
Restore a MySQL or MariaDB dump
A logical dump restores into a running MySQL or MariaDB instance of the same or a newer major version. You cannot import a dump into a server that is not running, and you cannot restore a MySQL 8 dump into MySQL 5.7 if it uses features the older server lacks.
Prerequisites: a working server, credentials with CREATE, INSERT, and (for a full restore) DROP privileges, and roughly the disk space the dump implies — restored tables are usually larger than the text file.
1: Confirm the dump is complete. A truncated file ends mid-statement. Check the last lines and look for the -- Dump completed comment that mysqldump writes. 2: Create an empty target database if the dump does not contain CREATE DATABASE: mysql -u root -p -e "CREATE DATABASE restored_db CHARACTER SET utf8mb4;". 3: Import the dump: mysql -u root -p restored_db < backup.sql. For a compressed dump, decompress in the pipe: gunzip -c backup.sql.gz | mysql -u root -p restored_db. 4: Watch for errors. The client stops on the first failed statement unless you pass --force, which skips errors and can leave partial data. Do not use --force on a first restore attempt. 5: Check success by counting rows in a few known tables and comparing them against the record counts stored in the dump's comments, or against your own notes from before the failure.
If the import fails with a privilege error, fix the grants rather than rerunning as root blindly. If it fails with a duplicate-key error, the target database was not empty — drop and recreate it, then retry. A common mistake is importing into the mysql system schema, which can corrupt the server's own accounts.
Restore a PostgreSQL dump
PostgreSQL has two dump flavors, and they need different restore commands. A plain SQL dump goes through psql; a custom-format dump goes through pg_restore.
1: Create the target database: createdb -U postgres restored_db. 2: For a plain dump: psql -U postgres -d restored_db -f backup.sql. 3: For a custom-format dump: pg_restore -U postgres -d restored_db backup.dump. 4: Expect and read the errors. pg_restore prints a warning for every object it cannot recreate, often because the owner role does not exist on the target server. That is usually harmless for the data, but check the summary line. 5: Verify by querying a table you know: SELECT count(*) FROM your_table;.
Restoring into a database with the same name as the original is fine, but restoring into the live production database is not. Create a side database, inspect the data, and only then decide how to cut over.
Restore a SQL Server .bak file
SQL Server restores through T-SQL or a management tool, and the process is stricter about paths and versions than the open-source engines.
1: Read the backup header first: RESTORE HEADERONLY FROM DISK = 'D:\backups\app.bak';. This returns the database name, backup date, and the SQL Server version that produced it. 2: Check the file list so you restore to valid paths: RESTORE FILELISTONLY FROM DISK = 'D:\backups\app.bak';. You will see logical data and log file names and their original directories. 3: Restore with relocation if the original paths do not exist on this machine: RESTORE DATABASE restored_db FROM DISK = 'D:\backups\app.bak' WITH MOVE 'app_data' TO 'D:\data\restored_db.mdf', MOVE 'app_log' TO 'D:\data\restored_db.ldf', RECOVERY;. 4: Use NORECOVERY instead of RECOVERY if you are chaining a full backup with later transaction-log backups; the last restore in the chain uses RECOVERY. 5: Confirm success by checking the SQL Server error log and querying the restored database.
A database cannot be restored over an existing one that is in use. If you see "database in use," take the database offline or restore under a different name. A backup from a newer SQL Server major version cannot be restored on an older one; that is a hard version boundary, not a configuration problem.
Handle point-in-time recovery when the backup is older than the incident
If you need the database as it stood at 09:14 yesterday, a nightly full backup alone will not do it. You need the full backup plus every transaction log or WAL archive covering the window, applied in order.
In SQL Server, restore the full backup with NORECOVERY, then each log backup in sequence with NORECOVERY, and finish with STOPAT = '2026-11-11T09:14:00' and RECOVERY. The STOPAT clause rolls the database forward to that instant; if the log chain has a gap, the restore fails at the gap instead of silently skipping it. In PostgreSQL, you restore the base backup, place the archived WAL files where the recovery configuration expects them, set a recovery target time, and start the server. The server replays WAL until it reaches the target. In MySQL, point-in-time recovery uses a full dump plus the binary logs: replay the dump, then apply the binary logs with mysqlbinlog up to a timestamp or position.
Point-in-time recovery only works if binary logging or WAL archiving was enabled before the incident. There is no way to reconstruct transactions that were never logged. If the archive was off, your recoverable point is the last full backup, and everything after it is gone.
The restore verification that catches most failures
A restore that completes without error is not the same as a usable restore. Verify with three checks, in this order:
1: Row counts. Compare the number of rows in your key tables against your own records or the counts recorded at backup time. 2: Referential integrity. Run a query that joins your main tables and look for orphaned rows. A dump that was taken during heavy writes can contain rows whose related rows were not yet committed. 3: Application-level spot check. Open the application against the restored copy and load a few known records. A database can pass counts and integrity checks and still fail because a stored procedure or view was not included in the dump.
The third check matters because many teams back up only tables and forget routines, triggers, and users. If your backup is mysqldump --tables output, your restore will be missing exactly those objects.
Why a perfect backup can still fail to restore
The failures below are not hypothetical edge cases. Each one is a routine cause of data loss.
Never-verified backups. A backup job that writes a file every night can produce empty or half-written files for months without complaint. The only reliable proof is a test restore onto a clean server. Run it on a schedule that matches your tolerance for loss. Wrong server version. A dump from a newer major version often fails on an older server. Keep the target restore environment at the same major version as production. Missing users and permissions. SQL Server restores fail when the logins referenced by the database do not exist on the target instance. The data restores; the application connections fail. Fix logins with ALTER USER ... WITH LOGIN after the restore. Character set mismatch. A dump in latin1 imported into a utf8mb4 database produces garbled text. Check the dump's charset directives and set the client connection accordingly. Disk space. Restores need more space than the backup file. A 2 GB compressed dump routinely unpacks to several times that in restored table size. Check free space before starting, not halfway through. The file is corrupt. Truncated dumps, backups interrupted by a server crash, and bit-rot on old drives all produce files that look valid and fail partway through. Verify checksums if you stored them, and test the file's integrity by a trial restore.
Use snapshots and managed-service restores correctly
If your backup came from a VM snapshot, a cloud managed database service, or a volume snapshot, the restore is handled by the platform, not by a database command.
A volume or VM snapshot restores by cloning it to a new disk or instance, then starting the database engine against it. You cannot import a snapshot with mysql or pg_restore. Managed database services usually offer point-in-time restore to a new instance, with a retention window set at service creation. The restored instance gets a new endpoint; you repoint the application after validation. One operational detail trips people: restoring a snapshot does not restore the network configuration, the instance's users, or its scheduled jobs unless those are part of the snapshot scope. Check what the platform includes before relying on it.
For any platform-based restore, record the restore's completion time and the database's clock at that moment. That pair of timestamps tells you how far back the data actually is, which is the first thing your users will ask.
Know when to stop and call a specialist
Some situations need a database recovery professional rather than another restore attempt. Stop and escalate when:
the backup file fails a trial restore with a corruption error and no second copy exists; the storage media itself is failing — clicking drives, unreadable sectors, or a volume that drops offline; the incident involves ransomware, and the attacker may have altered or encrypted both the live database and the backups; point-in-time recovery fails because the log chain has a gap you cannot account for.
In those cases, further commands can overwrite the evidence. Keep the original files untouched, work from a copy, and contact the vendor's support or a data-recovery service. Database recovery from a damaged file is a specialized service, and its costs usually depend on file size and damage type — confirm the quote before committing.
FAQ
Can I restore a backup into a database with a different name? Yes, on every engine covered here. Create a new empty database or instance, restore into it, validate the data, and only then switch the application over. Restoring into a differently named database is the safest way to inspect a backup before trusting it.
Do I need the same database version to restore? You need a server that can read the backup. SQL Server refuses backups from a newer major version on an older one. PostgreSQL and MySQL can often load dumps into newer versions, but features added in the newer version will not exist in the older one, so restoring into the same major version as the source avoids surprises.
How long should a restore take? It scales with the size of the restored data, not the size of the backup file, and with the disk's write speed. A large restore on slow storage can take hours. Time a restore of a representative slice first so your maintenance window is realistic.
Is a backup file enough, or do I need the logs too? The backup file gets you to the moment it was taken. Anything after that moment requires transaction logs or binary logs. If you need to recover recent changes, plan for both.
What if the backup file has a password or encryption? Encrypted backups need the key or password that was used at backup time. Store that credential separately from the backup. If the key is lost, the vendor cannot usually recover the data, and a professional recovery service may not be able to either.
This article is general technical information for database administrators and developers, not a guarantee that any particular backup will restore successfully. Recovery outcomes depend on your specific version, backup method, storage condition, and the state of the files, so confirm the procedure against your engine vendor's documentation and test on a copy before touching production data. For a failing disk, suspected ransomware, or a corrupted backup with no verified copy, consult a qualified database recovery professional and preserve the original files.