SQL Server Backup & Restore Command Generator
BACKUP DATABASE and RESTORE have dozens of options, and the mistakes are expensive: a log backup on a SIMPLE-recovery database, a restore that fails because the Windows file paths in the backup do not exist on Linux, a NOINIT file that quietly verifies the wrong backup set, or a point-in-time restore that recovers one step too early. Pick Backup or Restore, fill in the form, and this generator writes the T-SQL with properly bracketed identifiers and escaped strings, flags invalid combinations as you go, and gives you a matching sqlcmd one-liner. Everything runs in your browser — nothing is sent anywhere.
What to back up
WITH options
ℹ The path is resolved on the SQL Server machine (or container), not on your workstation, and the SQL Server service account needs write permission on the folder.
ℹ COMPRESSION is not available on SQL Server Express. Remove it there, or the backup fails.
Run it with sqlcmd
sqlcmd prompts for the password (or reads the SQLCMDPASSWORD environment variable) — never put -P on the command line. -b makes sqlcmd exit with a non-zero code when the backup or restore fails, so scripts and schedulers can detect it. Add -C when connecting to a server with a self-signed certificate (ODBC Driver 18 encrypts by default).
Do more than sql server backup & restore command generator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Choose Backup or Restore, then pick the Linux or Windows path preset so default folders and data-file paths match your SQL Server host.
- Fill in the database, backup type or restore type, destination or backup file, and toggle options such as COMPRESSION, CHECKSUM, encryption, WITH MOVE, REPLACE, STOPAT or the full restore chain — the script and warnings update live.
- Copy the T-SQL into your SQL editor, or copy the sqlcmd one-liner to run it from a shell, scheduled task or CI job.
Frequently asked questions
How do I back up a SQL Server database with T-SQL?
Run BACKUP DATABASE [MyDb] TO DISK = N'/var/opt/mssql/backup/MyDb_FULL.bak' WITH COMPRESSION, CHECKSUM, INIT, STATS = 10; for a full backup. Add DIFFERENTIAL to back up only the extents changed since the last full backup, or use BACKUP LOG for a transaction log backup — which requires the FULL or BULK_LOGGED recovery model and an existing full backup. Use COPY_ONLY for an ad hoc full backup that must not disturb the regular differential chain, and run RESTORE VERIFYONLY ... WITH CHECKSUM afterwards to confirm the file is complete and readable.
How do I restore a SQL Server backup under a different name or on another server?
First run RESTORE FILELISTONLY against the backup to read the logical file names. Then restore with RESTORE DATABASE [NewName] FROM DISK = N'...' WITH MOVE N'LogicalData' TO N'/var/opt/mssql/data/NewName.mdf', MOVE N'LogicalLog' TO N'/var/opt/mssql/data/NewName_log.ldf', RECOVERY. WITH MOVE is required whenever the original file paths do not exist on the target, such as a Windows backup restored on Linux. Add REPLACE only when you intend to overwrite an existing database, because it skips the safety check that protects an un-backed-up tail of the log.
How do I restore SQL Server to a point in time?
The database must use the FULL recovery model and you need an unbroken chain of backups. Restore the last full backup WITH NORECOVERY, then the latest differential WITH NORECOVERY, then each log backup in order WITH NORECOVERY, STOPAT = '2026-09-19T14:30:00', and finish with RESTORE DATABASE [MyDb] WITH RECOVERY. Enable the restore chain template above to generate every step. You can paste the script into Chat2DB (https://chat2db.ai/download) to run it against your server step by step and check the result with AI-assisted SQL.
