Batch file for auto backup

Posted on 2011-10-10
Last Modified: 2012-05-12
Can someone help me write a batch file to stop the SQL service, copy a data folder on my external drive and paste it to my desktop, then restart SQL service ?
Question by:raffie613
    LVL 9

    Assisted Solution

    @echo off
    net stop "mssqlserver" ---- replace this with the name of your server
    xcopy source destination /s /e
    net staart "mssqlserver"

    LVL 66

    Accepted Solution

    No points.....

    Syntax error above...

    net staart "mssqlserver"

    Should be

    net start "mssqlserver"

    Author Comment

    ok, but I am running SQL express 2005 on my workstation, do not have a SQL server. Is the Net stop the same? Just use my computer name?

    Expert Comment

    it should be something like SQLExpress instead.
    Anyway you can know it either by issuing a :
    tasklist /svc
    on the command line.
    Or running services.mscand right-click on the service. The name is the first field of the properties windows.
    LVL 5

    Assisted Solution

    The "net stop service"  and the "net start service" simply do start services that are running on you're machine.
    Probably the service  you want to stop in this case is name  "SQLEXPRESS" or something like that.
    Open mmc: services  and just lookup what the exact name is of the service.

    For example:  
    net stop SQLEXPRESS
    xcopy source destination /s /e
    net start SQLEXPRESS

    Author Comment

    ok, and I write this batch file in Notepad? Where do I save it so it can run every night? How do I set the time that it should run?

    LVL 77

    Expert Comment

    by:David Johnson, CD, MVP
    save it wherever you want and then set up task manager from administrative tools/task scheduler as shown here

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Window Update 6 36
    Video and audio capture on Windows 7 3 44
    7-zip 8 19
    Windows 10 share file 3 21
    After playing around with my ASUS 1215n ( Netbook, I finally managed to get smooth HD 1080p ( playback of videos on it. Second Generation Intel Atom (http://en.…
    Hi Friends, These registry tweaks will help you optimizing your Windows 7 system for any VDI. This will improve the machine performanance and can be used on normal systems also. These are few registry tweaks which will add value by enhancing the …
    This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
    The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now