Automatic SQL Backup/Restore

poloniouspolonious Member Posts: 64
edited 2009-12-16 in SQL General
Hi guys,

I'm trying to think of a good way of automating a backup/restore of a SQL database on a weekly/biweekly basis. Anybody know if this is possible through a SQL script or similar, or have any examples?

Any help would be great. Thanks.

Comments

  • DenSterDenSter Member Posts: 8,307
    Sure, use the SQL Server job scheduler. Read all about it in Books Online (Start, All programs, SQL Server, Documentation and Tutorials).
  • poloniouspolonious Member Posts: 64
    I should clarify, it's a backup of a Live DB and restoring to a Test DB to keep the test environment up to date.
  • DenSterDenSter Member Posts: 8,307
    DenSter wrote:
    Sure, use the SQL Server job scheduler. Read all about it in Books Online (Start, All programs, SQL Server, Documentation and Tutorials).
  • krikikriki Member, Moderator Posts: 9,115
    [Topic moved from 'NAV/Navision' forum to 'SQL General' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • strykstryk Member Posts: 645
    In SSMS you could quickly create the require TSQL scripts - as DenSter said, you'll find the details in "Books Online" & Co..
    Here an example:
    BACKUP DATABASE [Navision] -- Live DB
    TO  DISK = N'D:\Backup\LiveToTest.bak'
    WITH  DESCRIPTION = N'Full Backup for Test DB', 
    NOFORMAT, INIT,  
    NAME = N'LiveToTest', 
    SKIP, NOREWIND, NOUNLOAD,  STATS = 10
    GO
    
    RESTORE DATABASE [TestDB]  -- Test DB
    FROM  DISK = N'D:\Backup\LiveToTest.bak' 
    WITH  FILE = 1,  
    MOVE N'NAV_Data'   TO N'D:\Databases\TestDB.mdf',   -- change mapping
    MOVE N'NAV_1_Data' TO N'D:\Databases\TestDB_1.ndf', -- change mapping 
    MOVE N'NAV_Log'    TO N'E:\Databases\TestDB_2.ldf', -- change mapping 
    NOUNLOAD,  REPLACE,  STATS = 10
    GO
    
    Put something like this in a Job and execute as you like :thumbsup:
    Jörg A. Stryk (MVP - Dynamics NAV)
    NAV/SQL Performance Optimization & Troubleshooting
    STRYK System Improvement
    The Blog - The Book - The Tool
Sign In or Register to comment.