Backup SQL2008 with a script from task scheduller

Posted on 2009-12-29
Last Modified: 2012-05-08
Title says pretty much what I need - a script to run from windows task scheduller to backup a database.
Question by:Vaidas911
    LVL 15

    Expert Comment

    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    LVL 6

    Author Comment

    I like simple script as this:
    Use Master
    Declare @ToExecute VarChar(8000)
    Select @ToExecute = Coalesce(@ToExecute + 'Backup Database ' + [Name] + ' To Disk =     ''D:\Backups\Databases\' + [Name]   + '.bak'' With Format;' + char(13),'')
    [Name] Not In ('tempdb')
    and databasepropertyex ([Name],'Status') = 'online'

    My queston - is it possible to add parameters to rotate backups, ar should I use anoter script?
    LVL 75

    Accepted Solution

    the above will create a Full backup, you must create some  differential backups and the log backups too also thats just a  sql command, you need either OSQL or sqlCmd to execute a sql command from command prompt , if you check the link i provided, you can handle this easily using the sqlcmd utitlity ..

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
    After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now