Generate database backup

Asked

Viewed 252 times

7

In my project, I have a database that has a lot of record. So I wanted SQL Server to make a backup per day or per week. But I think the per day is better.

But how can I do this script to be programmed into SQL Server and it backup programmed, needing no one forcing him to do?

The version using SQL Server is 2012.

  • Dude, starts a code and when the doubts arise we help... Although I think there is how to change some configuration of SQL Server to do this.

  • So the point is, I have no idea how to do this. (. I’ve already researched, but I didn’t find anything that relevant. Or else I didn’t look right.

  • 3

    I think the question is valid. It’s short, objective, doesn’t depend on opinion, doesn’t require too broad a response and is something that many developers don’t know how to do. In addition to the +1 goes a favorite. P.S.: I am not the Renan who replied.

  • 1

    Exactly. There are many who do not know how to do it, including me, let alone where to start the research. And thank you very much for the favorite !

1 answer

8


If you just want a script Transact-SQL to do the backup, you can use something like:

USE SeuBanco;
GO
BACKUP DATABASE SeuBanco
TO DISK = 'Z:\SQLServerBackups\SeuBanco.Bak'
   WITH FORMAT,
      MEDIANAME = 'Z_SQLServerBackups',
      NAME = 'Backup Full do SeuBanco';
GO

The basic syntax is:

BACKUP DATABASE nomeDoBanco 
TO lugarOndeSeraGravado

See more details about the syntax for creating the script here and if you want to generate backups of differential from a full backup may use the clause DIFFERENTIAL.

But it is recommended you program one job to automate this using SQL Server Agent.

Right click on Jobs and then on New Job...

inserir a descrição da imagem aqui

In the guide General, in Name, write the name you find convenient for your job.

In the guide Steps, click on the button New for you to create the steps of your job.

inserir a descrição da imagem aqui

Enter a name for the step, type of the backup, the script and set up the schedule.

inserir a descrição da imagem aqui

For more details, have a look here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.