Moving the 'My Documents' folder (and others) to a different hard disk

Page 5 of 10 FirstFirst ... 34567 ... LastLast

  1. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #41

    Paul Black said:
    Thank you @Denis, it is very much appreciated. The reason I asked is because I intend to write a batch script to backup certain folders and files, and was thinking of looking into RoboCopy to achieve this. Like other scripts that I have written, I intend to tag the date and time [ in UK format ] to the filename. I need to investigate the RoboCopy parameters etc first. I will have a proper look at doing this over the weekend.
    Paul,

    My suggestion is that, if you want to prefix them with date-time, you will need a For loop sending
    - each identified folder to a subroutine where it can be sent to its destination individually but not renamed.
    - each identified file to a subroutine where it can be sent to its destination individually then renamed individually.

    I never use RoboCopy this way but it can be done.
    - You would still get a major benefit of RoboCopy in that creation dates & times would be preserved in the copies. If creation dates & times are not important to you then you might just as well use XCopy.
    - Doing it your way would allow accumulating backups and I imagine that is why you want to do it.

    Doing it my way suits that part of my file backup plan.
    - Hourly backup of all my own files within my Documents folder [and a few other select items] to a MicroSD card that lives in my computer, fits in an adapter on my keyring and can then be connected to my phone if I really needed to do so.
    - Weekly backup to alternate external HDDs. Whilst each RoboCopy command is a /MIRror, the use of two xHDDs means I deliberately have a slight accumulation of differing backups at any one time as well as the protection of dual-backups [I also alternate my system images between them and use a highly contorted WinZip routine to create and backup a differential backup of only those Documents etc files of mine that have changed since the last backup].
    - Ad hoc backup to my other computers. Both as a backup and to allow my computers to be used interchangeably - one computer is a tablet-with-keyboard that I use if I'm away.
    RoboCopy has built-in Help just like other commands do RoboCopy /?
    RoboCopy - MSDocs
    Robocopy - SS64

    I cannot find the TenForums thread where I posted details but I have also experimented with threading [the /MT:1 switch]. You can speed up backups to many destinations by using, just for example, /MT:32 but can only find out what works in any given set of circumstances by trying different values to see what works.
    - In some of my Robopy copy scripts, I check Robocopy Exit Codes - SS64 and repeat the command at a lower /MT: value if there has been a problem. So I only end up at /MT:1 for awkward destinations such as my tablet.

    Denis
      My Computer


  2. Posts : 386
    Windows 10 Pro (x64) 22H2 (OS Build 19045.3996)
    Thread Starter
       #42

    As an addendum ...

    ... for those not familiar with DOS commands and syntax, this website may be of help with clickable links which explain each command more fully - link: MS-DOS Commands

    Art
      My Computers


  3. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #43

    I've found what I could not find before. My advice about using RoboCopy threading is in
    my ditty - Using RoboCopy threading [post #10] - TenForums

    Denis
      My Computer


  4. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #44

    ArthurDent said:
    As an addendum ...... for those not familiar with DOS commands and syntax, this website may be of help with clickable links which explain each command more fully - link: MS-DOS Commands
    Art,

    SS64 is much, much better.
    - SS64 is maintained to keep it fairly up to date.
    - The site you mentioned is dated [in its copyright notice] as being no later than 2018 but I just had a look around and found two items that were incorrect even at that date.

    If you want a site that also helps with learning how to write batch files then I suggest Batch File Scripting Techniques - RobvdW

    Denis
      My Computer


  5. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #45

    Hello @Denis, thanks for the detailed explanation and advice!

    Try3 said:
    Doing it your way would allow accumulating backups and I imagine that is why you want to do it.
    I will sit down over the weekend and come up with a backup plan that accommodates my needs.

    What I am thinking of at present is creating a script that will basically [ pseudo code ] . . .

    [1] Set the parameter for todays date in the format dd-mmm-yyyy [ I might also include the time ].
    [2] Set the parameter for the destination drive.
    [3] Create a folder in the destination drive for each of the folders I want backed up with the todays date parameter added to the folder name. e.g. F:\Some_Folder_Name_10-Jul-2020.
    [4] Run the RoboCopy cmd's to populate the folders.

    This way I can run the backup script on a daily basis if I so wish.

    If I decided that I would need to backup the folders on a more regular basis [ more than once a day ] I will add a time parameter so that I can backup whenever I want.

    I am also going to include that if a folder is older than say three months, the folder gets deleted.
      My Computer


  6. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #46

    Try3 said:
    SS64 is much, much better - SS64 is maintained to keep it fairly up to date.
    I totally agree, I often visit that site to check that I am using the correct parameters and attributes!
      My Computer


  7. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #47

    Standard passable variables


    Paul Black said:
    [1] Set the parameter for todays date in the format dd-mmm-yyyy [ I might also include the time ].
    [3] Create a folder in the destination drive for each of the folders I want backed up with the todays date parameter added to the folder name. e.g. F:\Some_Folder_Name_10-Jul-2020.
    Paul,

    It's up to you but I do have a couple of observations
    1 If you work on the Last modified parameter instead then you will get less repetition in your backups because you could check if the renamed [date-time] folder/file existed in the destination and skip it if it did
    2 If you apply the Last modified [date-time] renaming to files instead of folders you will get less repetition in your backups and it will be easier to find your way around the backup if you want to recover a file.

    Last modified is a standard passable variable. Here is a list showing it and many others.
    - You can run it as a demo and can also read it to copy bits out of it [run the demo - drag and drop a test file on it; read it, select the batch file then right-click Edit]
    - These parameters can be passed when starting batch files and can be passed around inside them when calling sub-routines, such as when using a Call to a sub-routine in a For command.

    Standard passable variables.bat
    Code:
    :: This is a passable variables demo
    :: To run it, just drop a test file on it
    :: It does not do anything to the test file, it just displays variable values
    
    @echo off
    
    REM Batch file and test file parameters
    echo folder the batch file is running in %~dp0
    echo passed parameter %1
    echo passed parameter without quotation marks %~1
    
    REM Test file parameters
    echo fully qualified name %~f1
    echo drive %~d1
    echo path %~p1
    echo filename %~n1
    echo file extension %~x1
    echo short filename %~sn1
    echo fully qualified short name %~sf1
    echo short file extension %~sx1
    echo drive and directory %~dp1
    echo filename and extension %~nx1
    echo Date and time last modifed %~t1
    echo File attributes %~a1
    echo file size %~z1
    
    REM Some other variables that might be of interest
    echo %userprofile%
    echo Current folder on C drive if it has been used in this cmd session %=C:%
    echo Current folder on D drive if it has been used in this cmd session %=D:%
    echo Current folder without slash [except for system root folder] %CD%
    echo Current folder with slash %__CD__%
    echo Date %date%
    echo Time %Time%
    echo random number %Random%
    
    Pause at the end to examine its results

    I posted some other guidance at
    Manipulating variables in batch files - post #14 - TenForums
    and here are links to useful study materials for batch file scripting & PowerShell
    Batch file, PowerShell guides - post #13 - TenForums

    Denis
    Last edited by Try3; 11 Aug 2023 at 19:46.
      My Computer


  8. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #48

    Thanks @Denis for the detailed replies, links, and script [ I really like that ].

    I will try and find some time over the weekend to go through and absorb all the information that has been provided so as to get a better understanding of RoboCopy. It is good to learn new things, even at my age!

    Last night, when I thought about setting up a new more automated backup system in more detail, I decided that I was way over thinking this and unnecessarily making it too complicated, as you probably gathered from my previous posts!

    Therefore, I have come up with a more straightforward and structured method.

    It initially creates each of the hierarchy folders to be backed up with TODAYS date added [ hierarchy folder ONLY ] to the folder name.

    I decided to divert the RoboCopy output from the cmd prompt to a .txt file. One advantage of this is that you can check that each file was actually 100% copied across. This is shown as a percentage at the end of each line for each file [ does NOT apply to folders ]. The .txt file also shows ALL the folders [ directories ], files, and sizes etc copied, and has an overall summary at the bottom.

    Also, I can run this numerous times a day if I so wish.

    If I delete a file from the source and run the script again, it REMOVES the file from the destination [ if it was there prior to the current run obviously ].

    The .txt file of the diverted RoboCopy output is saved in the root of the main folder and opens automatically in Notepad on completion of the script. You then just close the .txt file and press any key to exit the script. I might actually setup another folder purely for the backup logs so I can always refer back to them.

    I have given up on the idea of adding code to delete folders more than x days old because it will be much easier, and safer, to delete them manually!

    For testing purposes, I used one folder as the source which contained a dozen sub-folders and about a 100 files.

    Here is the main part of the code . . .
    Code:
    @echo off
    
    for /f %%i in ('WMIC OS Get LocalDateTime /Value') do for /f %%j in ("%%i") do set "%%j"
    set "D=%LocalDateTime:~6,2%"
    set "M=%LocalDateTime:~4,2%"
    set "Y=%LocalDateTime:~0,4%"
    set "TODAY=%D%-%M%-%Y%"
    set "Batch_S=%userprofile%\Working Directory\Batch"
    set "Batch_D=F:\Batch - [ %TODAY% ]"
    set "Backup_Log=F:\Batch - [ %TODAY% ]\Backup_Log_%TODAY%.txt"
    
    :: I have some code here to run this option from a menu.
    
    :Backup
    
    if exist "%Backup_Log%" (del /f /q "%Backup_Log%" >nul 2>&1)
    echo. & echo  Backing up folders ^& files . . .
    md "%Batch_D%" >nul 2>&1
    RoboCopy "%Batch_S%" "%Batch_D%" /S /R:10 /XA:SH /MIR > "%Backup_Log%"
    echo  The folders ^& files have been backed up successfully. & echo.
    Notepad.exe "%Backup_Log%"
    echo ^>Press ANY key to EXIT . . . & pause >nul
    goto :Exit
    I could ONLY get this to work by using the RoboCopy parameters . . .
    Code:
    /S /R:10 /XA:SH /MIR
    It did not work using . . .
    Code:
    /S /R:10 /MT:1 /DCOPY:DAT /XA:SH /MIR
    I had to remove the bolded code above because it gave errors!

    As I have said, I will go through the information provided along with investigating why this is the case.
      My Computer


  9. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #49

    Hello @Denis,

    I just setup an OpenOffice Calc worksheet [ took about half an hour ] to save time and help when adding additional folders. All I have to do now is to put the hierarchy folder name into a cell and it automatically creates the three bottom set parameter lines in the code and the md and RoboCopy lines. All I have to do then is to copy & paste them directly into the .bat file. I thought I would do this as a quick and easy way to add additional folders to the script and know that ALL the parameters and lines of code are correct!
      My Computer


  10. Posts : 386
    Windows 10 Pro (x64) 22H2 (OS Build 19045.3996)
    Thread Starter
       #50

    @Try3

    Denis,

    Can you remember, back in February when you introduced me to Robocopy, you mentioned that once you were happy that Robocopy was working as planned, you could run Robocopy without the Command Window showing and with an icon in the Notification Area.

    Can you find that post? I'm trawling through the February posts and haven't found it so far.

    Cheers,

    Art
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:20.
Find Us




Windows 10 Forums