Results 1 to 10 of 10
  1. #1
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts

    Need batch file to restore saved batch files

    Part of a backup Batch (.bat) file I have has the following commands to save files to a directory named with the date and time:


    @echo off
    :: variables
    set drive=D:\working
    SET dateNtime="%date:~0,2%-%date:~3,2%-%date:~6,6%_%time:~0,2%-%time:~3,2%"
    set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
    echo ### Backing Up Firefox Directories...
    %backupcmd% "D:\Mozilla Firefox" "%drive%\%dateNtime%"
    echo Backed Up Firefox Directories Complete - Your Backup is located at %drive%

    Can someone help me write a batch menu or file that will let me choose a directory from the above backed up folders to restore?

    I need to have a choice to select the directory to be restored.
    In the saved date and time directories, there are two saved different folders. One for the Firefox profile folder and the other for the program folder.

    The backup commands work for me....I need commands to select a directory to restore.
    GiddyUpGo "Don't look back. That is not the direction you are going!"

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,199
    Thanks
    48
    Thanked 987 Times in 917 Posts
    Batch files don't lend themselves to interactive uses so it's likely to be a manual method. Plus a restore is not something to be done lightly and I would always want to do it by hand.

    cheers, Paul

    p.s. The "/d" switch is not required because you create a new directory for every backup.

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    It's fairly straightforward to write such a BATch file - the difficulty is usually in the exact problem definition!

    The questions which immediately spring to mind are:
    1) Are you selecting the Firefox directories to restore by date and time? That is, do you want to type the entire date and time to select it? (Good luck!)
    2) how many of these backup directories are you likely to have (more than about 10 would be difficult, more than about 20 might not fit into your command prompt window without you stretching it)?
    3) do you want to restore both the program directory and the Firefox profile directory, or maybe one or the other? You'd need to supply the name(s) of these directories unless you wanted both to be restored.

    The way I'd approach it would probably, in a FOR statement, to do a DIR /AD of the backup directory, sorted in chronological (or reverse chronological) order, and use SET /P to select the one you want.

    I have a backup directory of ten sets of desktop icons layouts, each saved when I logon each day. The file numbers wrap round. I display the file names in date/time order and select the icon layout I want to restore to the desktop as a number. Your problem is similar, but with directories rather than files!
    Last edited by BATcher; 2012-01-08 at 05:21. Reason: got HTML tags appearing all through the post!
    BATcher

    Time prevents everything happening all at once...

  4. The Following User Says Thank You to BATcher For This Useful Post:

    GiddyUpGo (2012-01-08)

  5. #4
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts
    Quote Originally Posted by BATcher View Post
    It's fairly straightforward to write such a BATch file - the difficulty is usually in the exact problem definition!

    The questions which immediately spring to mind are:
    1) Are you selecting the Firefox directories to restore by date and time? That is, do you want to type the entire date and time to select it? (Good luck!)
    2) how many of these backup directories are you likely to have (more than about 10 would be difficult, more than about 20 might not fit into your command prompt window without you stretching it)?
    3) do you want to restore both the program directory and the Firefox profile directory, or maybe one or the other? You'd need to supply the name(s) of these directories unless you wanted both to be restored.

    The way I'd approach it would probably, in a FOR statement, to do a DIR /AD of the backup directory, sorted in chronological (or reverse chronological) order, and use SET /P to select the one you want.

    I have a backup directory of ten sets of desktop icons layouts, each saved when I logon each day. The file numbers wrap round. I display the file names in date/time order and select the icon layout I want to restore to the desktop as a number. Your problem is similar, but with directories rather than files!
    Your #1 question is my problem. I have a batch file that saves or restores 2 directories at the same time. The backups names never change. I save 4 backups only. I have a menu that lets me select the backup.
    As you have stated, I may not be able to have a menu that would select always changing names such as the date and time names.
    I backup my Firefox profile:
    C:\Users\LR\Application Data\Mozilla\Firefox\Profiles\cgilqkzq.default
    and my Firefox directory:
    F:\Mozilla Firefox
    I could not figure out a menu that would let me choose always changing saved names. I just thought someone here could.
    Thank you for your reply

  6. #5
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    In your original BATch file, it appears to me that you are only backing up your Firefox directories from D:\Mozilla Firefox.
    So are you previously copying files from the directories
    C:\Users\LR\Application Data\Mozilla\Firefox\Profiles\cgilqkzq.default
    and
    F:\Mozilla Firefox
    to
    D:\Mozilla Firefox
    ?
    And then copying to
    D:\Working
    ?

    You can see what I mean about needing to define the problem correctly!

    (And, out of interest, what is produced by
    %date:~0,2%-%date:~3,2%-%date:~6,6%
    ?
    I would have expected this to be
    %date:~0,2%-%date:~3,2%-%date:~6,4%
    giving (in the US) mm-dd-yyyy )
    BATcher

    Time prevents everything happening all at once...

  7. #6
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Right, here's some sample code:
    Code:
    @echo off
    :: sample batch file to list and choose directories
    ::   this batch file can be located anywhere 
    
    setlocal enabledelayedexpansion
    cls
    
    set ctr=1
    echo List of directories in D:\working which can be restored
    for /f %%a in ('dir /ad /b /od d:\working') do (
      echo   !ctr!  %%a
      set /a ctr+=1
    )
    
    :loop
    echo Please give the number of the directory you wish to have restored (1-4),
    set /p choice="or type  x  then Enter to eXit immediately "
    if "%choice%"=="" goto loop
    if /i %choice%==x goto exit
    if %choice% lss 1 goto loop 
    if %choice% gtr 4 goto loop
    echo Your choice is #%choice%
    
    :: obtain the directory name into a variable restdir
    set ctr=1
    for /f %%a in ('dir /ad /b /od d:\working') do (
      if !ctr!==%choice% set restdir=%%a
      set /a ctr+=1
    )
    echo Your chosen directory is %restdir%
    
    :: code here to do the actual restore....
    
    
    :exit
    endlocal
    and here is the output, when I pressed 3 and Enter:
    Code:
    List of directories in D:\working which can be restored
      1  01-08-2012_15-23
      2  01-07-2012_17-18
      3  01-06-2012_16-55
      4  01-05-2012_14-08
    Please give the number of the directory you wish to have restored (1-4),
    or type  x  then Enter to eXit immediately 
    Your choice is #3
    Your chosen directory is 01-06-2012_16-55
    Hope that may help?
    BATcher

    Time prevents everything happening all at once...

  8. The Following User Says Thank You to BATcher For This Useful Post:

    GiddyUpGo (2012-01-09)

  9. #7
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts
    Very nice code BATcher.
    I did not understand that you would create the file for me. The example I gave for the backup was a working test file, not ready for me to use yet.
    You made me feel very special! Thank You!
    I will work on your code to make it work for me.

    My 2 backups would be FROM:
    "F:\Mozilla Firefox"
    "C:\Users\LR\Application Data\Mozilla\Firefox\Profiles\cgilqkzq.default"

    The backups would be made TO Drive D:\Mozilla Firefox.
    I currently have two sub directories in the D:\Mozilla Firefox directory
    "Firefox" (directory for the "F:\Mozilla Firefox")
    "Profile" ("C:\Users\LR\Application Data\Mozilla\Firefox\Profiles\cgilqkzq.default")

    The date and time directories would be placed under these directories.

    That is how I now have them working with just the static names that never changes. One menu for backups and another for restores. I never got around to just making just one menu.

    Any other way would be great as long as the folders are saved from Drive F and Drive C to my data Drive D:

    The code you gave me is a great start! Now for me to get it all together and get it working.

    I am sure you are wondering why I need so many directories....I play around with Firefox a lot. New upgrades, trying new extensions, and so on.

    Again you made me feel very special in helping me.....Thank you again!

  10. #8
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    I hope you get it working successfully in your situation!
    BATcher

    Time prevents everything happening all at once...

  11. #9
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts
    Quote Originally Posted by BATcher View Post
    I hope you get it working successfully in your situation!
    Thanks!
    I thought you might like to know that I now have the dated backups and restores working perfect.
    I used a menu to run each of our codes twice.
    Used your basic code for the Restores, once for the profile and then again for the Program, one after the other.
    Same way for the Backups using my code.
    Maybe not very pretty, but this way it works.
    I have given you credit in my menu for your code too.
    GiddyUpGo "Don't look back. That is not the direction you are going!"

  12. #10
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts
    I'm pleased you have it working for you!
    BATcher

    Time prevents everything happening all at once...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •