Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Database backup script issue  (Read 5176 times)

0 Members and 1 Guest are viewing this topic.

jormeno

    Topic Starter


    Rookie

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    Database backup script issue
    « on: November 13, 2013, 10:44:52 AM »
    Hello everyone,

    I created a batch script with the help of others and modified it to fit my needs. Anyways the first portion of the script works, it creates the backup, and compress it properly but the issue i am having is trying to delete the .bak file after its been compressed, so All i want to see is the zip file. I have searched long and hard for this answer but can't seem to get it right.


    @echo Creating Backup folder located in c:/
    mkdir C:\Backups
    If exist "C:\Backups" ECHO Directory exists!
    @echo Backing up your Database....This may take awhile.....
    sqlcmd -S Servername\sqlinstancename -i backupDBscript.sql
    SET SQL_Backup_script=C:\Path to file
    SET MY_Path=C:\path to backup
    set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
    for %%x in (*.bak) do cscript "%SQL_Backup_script%\zip.vbs" "%MY_PATH%\%%x" "%MY_PATH%\DB_%mydate%.zip"
    del /Q/R "C:\Backups\*.bak"
    @pause
    You won't know unless you try.

    jormeno

      Topic Starter


      Rookie

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: Database backup script issue
      « Reply #1 on: November 13, 2013, 11:57:50 AM »
      I did add del "C:\Backups\*.bak" /q  in a test batch file that worked but when i put it in the original batch file it didn't delete it
      You won't know unless you try.

      LogicVein



        Newbie

        • Experience: Expert
        • OS: Windows 7
        Re: Database backup script issue
        « Reply #2 on: November 13, 2013, 03:28:45 PM »
        /R is not a valid parameter or switch for the DEL command in batch code (command-line). /Q makes it run quietly without prompt and /F would force it to delete read-only files if that is what you were trying to achieve. What might help you while you are learning is to open command prompt and simply type the command you want help on and follow it with [space] /? (i.e. DEL /?)

        Try DEL /Q /F "C:\Backups\*.bak"

        jormeno

          Topic Starter


          Rookie

          Thanked: 1
          • Experience: Familiar
          • OS: Windows 7
          Re: Database backup script issue
          « Reply #3 on: November 14, 2013, 07:12:48 AM »
          That didn't work :/
          You won't know unless you try.

          jormeno

            Topic Starter


            Rookie

            Thanked: 1
            • Experience: Familiar
            • OS: Windows 7
            Re: Database backup script issue
            « Reply #4 on: November 22, 2013, 08:37:49 AM »
            bump
            You won't know unless you try.

            jormeno

              Topic Starter


              Rookie

              Thanked: 1
              • Experience: Familiar
              • OS: Windows 7
              Re: Database backup script issue
              « Reply #5 on: December 18, 2013, 09:50:35 AM »
              bump
              You won't know unless you try.

              jormeno

                Topic Starter


                Rookie

                Thanked: 1
                • Experience: Familiar
                • OS: Windows 7
                Re: Database backup script issue
                « Reply #6 on: January 14, 2014, 01:00:39 PM »
                bumpity bump
                You won't know unless you try.

                Squashman



                  Specialist
                • Thanked: 134
                • Experience: Experienced
                • OS: Other
                Re: Database backup script issue
                « Reply #7 on: January 14, 2014, 02:04:49 PM »
                I am confused as to why you are hard coding the path C:\backup.  Shouldn't all your .bak files be in the MY_PATH directory?
                The code you were given should work as long as your .bak files are in that folder.
                Code: [Select]
                DEL /Q /F "C:\Backups\*.bak"

                jormeno

                  Topic Starter


                  Rookie

                  Thanked: 1
                  • Experience: Familiar
                  • OS: Windows 7
                  Re: Database backup script issue
                  « Reply #8 on: January 29, 2014, 01:11:09 PM »
                  I was placing file in wrong path Thanks guys!
                  You won't know unless you try.