Please, help with batch files

Discussion in 'backup, imaging & disk mgmt' started by Decopi, Jun 14, 2023.

  1. Brian K

    Brian K Imaging Specialist

    For backups, you just run the same Robocopy batch file everyday. My batch file is scheduled and I don't see it running. It only copies files/folders that have changed. Hence the 1 minute backup time. Of course if I'd added 10 GB of files to the Data partition then the backup time would be longer. I don't seem to have your complicated setup.

    I also use backup images so it's probably overkill. There is plenty of drive space and it's a hobby. Automated anyway.

    Because of the potential Robocopy bug I don't copy from the root of D:\ drive. Here is my batch file...

    Code:
    set source=D:\My_files
    set target=H:\TeraByte_TBI_Backups\DATA_Backup\My_files_backup
    set rlog=H:\data-rclog.log
    robocopy.exe "%source%" "%target%" *.* /mir /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32 /log:"%rlog%"
    set source=
    set target=
    set rlog=
    All my data is in D:\My_files
     
  2. Brian K

    Brian K Imaging Specialist

    Regarding backups, I multi-boot, sometimes up to 30 OS partitions. These partitions are backed up by imaging. There is a single data partition that is seen by all OS. Each OS only sees itself. All other OS are hidden from the booted OS.

    UFDs aren't needed for restores as restore partitions can be booted.
     
  3. Brian K

    Brian K Imaging Specialist

    Robocopy is fast in my computer. Copies at 2 GiB per second.
     
  4. Decopi

    Decopi Registered Member

    Thank you for sharing your strategy!
    Believe me, now I'm incredible curious about your backup batch scheme. I found it super interesting.
    But I don't have enough know-how, and I don't want to bother you with my lay questions.
    I just want to say that I have the impression I can improve a lot my batch backup strategy by stealing some ideas from your scheme : )

    That said, please let me abuse a bit, asking another simple question:
    I'm using most of the batches you already shared with me in this post (thank you!).
    But I have one drive (J:\), a little bit messy, because I can't format J:\, it has has several folders and sub-folders that I don't want to touch them (for example: System Volume Information, $RECYCLE.BIN, Whatever One, Media Stuff\Whatever Two).
    And in order to gain speed in the backup process, I'm trying to test a different approach, not by using your "MD F:\delete" etc, but by using this:

    @Echo Off
    SETLOCAL
    SET "sourcedir=J:\"
    SET "keepdir1=System Volume Information"
    SET "keepdir2=$RECYCLE.BIN"
    SET "keepdir3=Whatever One"
    SET "keepdir4=Media Stuff\Whatever Two"
    FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" RD /S /Q "%%a"
    GOTO :EOF

    Unfortunately the code above is deleting all folders inside J:\. Obviously I'm doing something wrong, and the "keepdir" is not working. Surely my syntax is wrong somewhere.
    Yeah, I know, I can use your "MD F:\delete" etc.
    But I really would like to try this different approach, using "keepdir", deleting everything except what is inside "keepdir".

    If by chance you can help, it'll be great.
    Thank you in advance for your patience!
     
  5. Brian K

    Brian K Imaging Specialist

    Decopi,

    I can't help with that script. Apart from saying there is no SET for "keepdir". So the FOR /d line looks incorrect.

    Are you imaging your various data partitions? If they aren't being imaged individually I prefer to have a single data partition with specific folders for my data. To make backup easy, that gives me one backup instead of multiple backups, I backup the entire drive without exclusions. For items that don't need a backup, such as multiple copies of Rambo, I have another partition.
     
  6. Decopi

    Decopi Registered Member

    Yeah, I also thought about this possibility, make a redistribution of my folders, separating partitions for backup and other partitions that don't need backups.
    My problem is that my partitions follow the logic of subjects. So, I can redistribute folders, but it will be my last choice.

    And I still have your "MD F:\delete" etc. It works. It can delete drive content, avoiding specific folders.
    I just was trying a different approach, because my partitions are huge in size. And the "MD F:\delete" etc strategy takes time and uses lot of I/O.

    By the way, I always thank you for your great help, was very useful to me.
     
  7. Brian K

    Brian K Imaging Specialist

    I like the simple approach. My daily backups happen if I'm here or not. I don't want to be tweaking them.

    I think data should be in its own partition and not in the OS partition. The OS partition should be lean and mean. This makes for faster OS image/restore.

    I don't have Desktop, Downloads, Documents, Music, Pictures or Video files in the OS partition. It's easy to change the location of these folders.
     
  8. Decopi

    Decopi Registered Member

    Totally agree! I have similar approach.
    All my data is in several different partitions.
    OS has its own isolated partition.

    I also try to use portable software, as much as possible.
    I'll say 85% of my programs are portable. And all of them are in a different partition (not at OS partition).
    This scheme is not great only for backup, but also for security.
    And if for any reason the OS decides to go "KAPUT" (bug, death screen etc), by reinstalling the OS partition you're ready to go in few minutes. Worse case, you change your drive to other device, and the same, you're ready in few minutes.

    Separating OS partition from other partitions seems to me perfect.
     
  9. Brian K

    Brian K Imaging Specialist

    For those considering moving their data files out of the OS partition...

    In the Win10/11 Navigation pane on the left, in "This PC"...
    The following are icons to be dealt with....

    Desktop
    Documents
    Downloads
    Music
    Pictures
    Videos


    Right click the item, Properties, Location tab
    Change C to D (so you now might have D:\Users\Brian\Desktop)
    Apply
    Yes to "Create Folder"
    Yes to "Move Folder"
    OK

    Continue with Documents, etc.

    Have a backup image before you commence moving files. Just in case of doing something stupid.
     
  10. Brian K

    Brian K Imaging Specialist

    This is a TeraByte TBOSDT Pro script than can delete and recreate a NTFS partition. The script will do the formatting.
    I had 5 partitions on the drive. I deleted and recreated Partition ID 0x03 on HD2.

    Code:
    del partition 2 0x03 /y
    add partition 2 0x80 20000 7 datab /a=2048
    set part num 2 0x05 2
    It's not worth buying TBOSDT Pro unless this is very important to you.
     
  11. Decopi

    Decopi Registered Member

    @Brian K, always thank you for your help!

    Please, back to my question about deleting a drive content but with folder exceptions. I'm incredible close to solve what I need. This is my latest batch:

    Code:
    @Echo Off
    md J:\empty
    robocopy /mir J:\empty J:\ /xd "Folder One" "Folder Two" "System Volume Information" $Recycle.bin
    robocopy.exe I:\ J:\ *.* /mir /XD "Folder One" "Folder Two" "System Volume Information" $Recycle.bin /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32
    exit
    I have two drives, I:\ is my main drive, and J:\ is the backup drive for I:\
    My batch above starts by deleting everything inside drive J:\, except the following folders: "Folder One", "Folder Two", "System Volume Information", "$Recycle.bin"
    Then my batch copies drive I:\ (except "Folder One", "Folder Two", "System Volume Information", "$Recycle.bin") and pastes everything inside J:\
    Works like a charm.

    Please, I need the last two steps:

    1. Instead of "Folder One", how can I use a path with a sub-folder like "Folder One/Folder One Sub Folder"?

    2. I liked your batch that only copies/pastes files that are new or they changed. So, please, how can I replace my

    Code:
    robocopy.exe I:\ J:\ *.* /mir /XD "Folder One" "Folder Two" "System Volume Information" $Recycle.bin /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32
    with a command line that:
    It will copy everything inside I:\, but it will paste at J:\ only files that are in I:\ but are not in J:\
    And also it will copy files from I:\, it will paste on J:\ even if the files already exists at J:\ (files with same name), but it will replace files at J:\ only if something (size, date, whatever) changed

    The general idea is to copy everything inside I:\ and to paste inside J:\ but only: a) If the files are not in J:\ and b) Only if the files exists at J:\ but are different from files in I:\

    Hope you can help me! These are my last two steps I need to finish my batches.
    Thank you a lot in advance!
     
    Last edited: Jun 17, 2023
  12. Brian K

    Brian K Imaging Specialist

    You are getting close. More trial and error is needed.

    Robocopy switches...

    https://learn.microsoft.com/en-us/w...windows-commands/robocopy?redirectedfrom=MSDN

    You could experiment with /e instead of /mir

    Another way of emptying a folder is to copy the contents of an empty folder (that is, nothing) to the target folder. So create a folder called EMPTY (nothing in it) and use a line like this...

    Code:
    robocopy.exe "D:\My_files\Storage\Keep\S to Z\T\TeraByte apps\WinPE\EMPTY" "C:\Windows\SoftwareDistribution\Download" /mir /r:0 /log:"D:\My_files\Users\Brian\Desktop\Folders\z-robocopy.log"
    In your batch files you can have a line with only one word...

    pause

    The batch file will stop at that point and you can check the Command window for errors etc. Pressing "any key" continues the batch file.

    Keep your batch lines consistent...

    Don't have switches in front of Source. It could have unintended consequences.
     
  13. Brian K

    Brian K Imaging Specialist

    To copy a single file...

    Code:
    robocopy.exe c:\folder1 d:\folder2 transfer_this.txt
     
  14. Brian K

    Brian K Imaging Specialist

    If there are spaces in the source or target path, wrap the path with " "
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice