+ Post New Thread
Results 1 to 11 of 11
Windows Thread, Is this possible? in Technical; My boss today saw me playing around with Robocopy at work, I was using it to backup my laptop to ...
  1. #1

    Join Date
    Nov 2011
    Location
    Ramsgate
    Posts
    38
    Thank Post
    12
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Question Is this possible?

    My boss today saw me playing around with Robocopy at work, I was using it to backup my laptop to one of our servers and he asked me if it was possible to create a script that could be used to create a folder on an external hard drive with the file name based upon the current date and time and then use Robocopy to backup specfic folders to. Not only that it would have to do a full backup initally followed an incremental back there after.

    ie:
    Backup1-1-11 Full backup
    Backup2-1-11 Incremental backup
    Backup2-1-11 Incremental backup

    and so on...

    Now my scripting knowledge is basically nil apart from doing logon scripts but I think it is possible but I need to find a definate answer.

  2. #2

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    1,826
    Thank Post
    104
    Thanked 449 Times in 308 Posts
    Blog Entries
    2
    Rep Power
    262
    Pretty straightforward. If no-one posts a solution in the meantime, I'll post a sample script tomorrow.

  3. Thanks to jinnantonnixx from:

    rshortland (25th November 2011)

  4. #3

    Join Date
    Nov 2011
    Location
    Ramsgate
    Posts
    38
    Thank Post
    12
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Quote Originally Posted by jinnantonnixx View Post
    Pretty straightforward. If no-one posts a solution in the meantime, I'll post a sample script tomorrow.
    Thank you I've found a script online that I'm trying to modify as well but I think it is a bit on the complicated side. It seems to work but it uses a lot of variables and seems to have written to backup someones user profile which is useful but not what I'm really after

  5. #4

    m25man's Avatar
    Join Date
    Oct 2005
    Location
    Romford, Essex
    Posts
    1,608
    Thank Post
    49
    Thanked 444 Times in 330 Posts
    Rep Power
    136
    Didn't somebody write a GUI front end for Robocopy?
    Microsoft Robocopy and Microsoft Robocopy GUI in Windows 7 & Vista | WinVistaClub

  6. #5


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,233
    Thank Post
    218
    Thanked 813 Times in 695 Posts
    Rep Power
    274
    Quote Originally Posted by m25man View Post
    Would that be richcopy

  7. #6

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    1,826
    Thank Post
    104
    Thanked 449 Times in 308 Posts
    Blog Entries
    2
    Rep Power
    262
    This should get you there.

    You can remove the echos and comments if you like; they're for testing so you can see how it works.


    Code:
    :: script to robocopy files to a folder named after the current date
    
    :: set the time & date into a variable
    for /f "tokens=1,2" %%a in ('time/t') do set time=%%a
    for /f "tokens=1,2" %%a in ('date/t') do set date=%%a
    
    
    :: date has '/' characters which we can't use in a file or folder
    :: use the 'set' command to substitute the / to a -
    set date=%date:/=-%
    
    
    :: time has ':' characters which we can't use in a file or folder
    :: change to a '.'
    set time=%time::=.%
    
    
    echo Time=%time%
    echo Date=%date%
    
    
    :: you can use the date as is, or we can split it up into YYYYMMDD
    :: to make file sorting more logical
    
    for /f "tokens=1,2,3 delims=-" %%a in ('echo %date%') do (
    	set dd=%%a
    	set mm=%%b
    	set yyyy=%%c
    )
    
    echo DD=%dd%
    echo MM=%mm%
    echo YY=%yyyy%
    
    
    
    :: set the destination folder
    
    :: if you don't care about file sorting
    set destfolder=X:\BACKUPS\%date%\FULL or whatever
    
    :: if you want full sorting on YYYYMMDD
    set destfolder=X:\BACKUPS\%yyyy%%mm%%dd%\FULL or whatever
    
    
    :: if you want full sorting + time
    set destfolder=X:\BACKUPS\%yyyy%%mm%%dd%\%time%\FULL or whatever
    
    
    
    
    
    :: call robocopy
    robocopy <source folder> %destfolder% /E
    It assumes you're using the European date model (DD/MM/YYYY) not the crazy American date.
    Last edited by jinnantonnixx; 25th November 2011 at 10:57 AM.

  8. 2 Thanks to jinnantonnixx:

    Jollity (25th November 2011), rshortland (25th November 2011)

  9. #7

    Join Date
    Nov 2011
    Location
    Ramsgate
    Posts
    38
    Thank Post
    12
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Thank you for that I'll give it a go when I get back to work on Monday

  10. #8

    Join Date
    Nov 2011
    Posts
    214
    Thank Post
    260
    Thanked 22 Times in 18 Posts
    Rep Power
    10
    Neatly done, jinnantonnixx. I did not know the trick of using tokens, and it might help me with a script bug I need to fix.

    But haven't you missed out part of what rshortland was asking for? He wanted the copies after the first to be incremental, with only changed files. The only way I can see to do that would be to use the archive attribute, which will not work if anything else is using it - ie if you do a separate incremental backup on those files that relies on the archive bit, then altering it when you do your robocopying will mean the files get missed out of that backup. You need to make sure the archive attribute is unset on all the files after the initial copy, I think the command for that is:
    Code:
    attrib -a <source folder> /S /D
    Then for the incremental copies after the initial copy, use the /m switch with the robocopy command.
    Code:
    robocopy <source folder> %destfolder% /E /M

  11. #9

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    1,826
    Thank Post
    104
    Thanked 449 Times in 308 Posts
    Blog Entries
    2
    Rep Power
    262
    You're quite right, I did miss the requirement for incremental copies.

    As you suggest, the /M option will work, copying files that changed since your last copy.
    /M :: copy only files with the Archive attribute and reset

    Also, the /MAXAGE option in Robocopy is a more absolute way of doing this.
    /MAXAGE:n : MAXimum file AGE - exclude files older than n days/date.
    /MINAGE:n : MINimum file AGE - exclude files newer than n days/date.
    (If n < 1900 then n = no of days, else n = YYYYMMDD date).

    Note the option which allows the use of YYYYMMDD. We've already calculated this in our script, so we can use this option quite easily.

  12. #10

    Join Date
    Nov 2011
    Posts
    214
    Thank Post
    260
    Thanked 22 Times in 18 Posts
    Rep Power
    10
    /MAXAGE probably would be better than using /m. For a start it avoids the risk of problems with something else relying on the archive attribute.

    However the YYYYMMDD date the script calculates is the current date, whereas you would want to give MAXAGE the date of the last backup. Perhaps saving the date in a file each time the script is run would work?

    Another potential bug might be to rely on only the date, rather than date and time of the last backup. Example:
    14/11/11 10:00 - save file X
    14/11/11 11:00 - run the robocopy script - file X will be saved in the 20111114 folder
    <File X is not altered>
    16/11/11 11:00 - run the robocopy script again with /MAXAGE 20111114. File X is saved in the 20111116 folder, even though it hasn't changed since we last ran the script.

    Maybe that is not a problem, but it does mean the backups will not be strictly incremental. Oddly I cannot see an option for robocopy to exclude files older than a date and time.

  13. #11
    mjs_mjs's Avatar
    Join Date
    Jan 2009
    Location
    bexleyheath, london
    Posts
    1,004
    Thank Post
    37
    Thanked 108 Times in 93 Posts
    Rep Power
    36
    I have a batch file that can do this - it doesn't use the date modified bit - but does use the date from the file system, that usefull at all?

SHARE:
+ Post New Thread

Similar Threads

  1. Is this possible - membership?
    By Diffie in forum EduGeek Joomla 1.5 Package
    Replies: 11
    Last Post: 16th March 2009, 01:07 PM
  2. Is this possible?
    By laserblazer in forum General Chat
    Replies: 6
    Last Post: 3rd January 2009, 03:51 AM
  3. New Mac network - is this possible?
    By sidewinder in forum Mac
    Replies: 28
    Last Post: 28th August 2008, 01:19 AM
  4. Replies: 1
    Last Post: 26th August 2008, 01:49 PM
  5. Is This Possible?
    By Gambit in forum Scripts
    Replies: 7
    Last Post: 18th April 2007, 09:36 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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