Override file while backup database

juergen d picture juergen d · Dec 4, 2012 · Viewed 48.1k times · Source

I want to back up a database using this code

sqlcmd -S servername -Q "BACKUP DATABASE [DBName] TO DISK = 'C:\backup.bak'"

It works. But if the backup file already exists, the data gets appended to the file instead of replacing the file. Every time I call BACKUP DATABASE the file gets bigger.

Is there an option for BACKUP DATABASE to force a replace?

Answer

bummi picture bummi · Dec 4, 2012
sqlcmd -S servername -Q "BACKUP DATABASE [DBName] TO DISK = 'C:\backup.bak' WITH INIT"