I'm supposed to backup a Windows 10 computer. This means copying specific filetypes e.g. .pdf, .doc, .xls, .jpg etc.
I've tried with xcopy but the backup doesn't get complete due to the fact that the computer apparently has folderpaths that are longer than 254 characters.
Therefore I googled, and found Microsofts robocopy, which can handle that particular problem (among others).
Robocopy is a foldercopy utility and not so much a filecopy utility, but with some parameters it should be able to solve the problem.
I created a batch file witch contains these two lines (+ all the rest of the relevant filetypes)
robocopy c:\ d:\B20180602\ *.pdf /s /A-:SH
robocopy c:\ d:\B20180602\ *.doc /s /A-:SH
The odd thing is that it now copies without problems (regarding to foldernames larger than 254 characters), but the final result of this backup is incomplete. There are several subfolders that aren't copied.
Is there anybody that can give me a hint? Thanks in advance.
UPDATE #1 *
After #selbie's advice I ran this one particular command (as Administrator):
robocopy c:\ d:\B20180602\ *.pdf /s /A-:SH
With the following result:
Total Copied Skipped Mismatch FAILED Extras
Dirs : 761465 761351 1 0 113 0
Files : 1233 1233 0 0 0 0
Bytes : 1.464 g 1.464 g 0 0 0 0
Times : 1:58:47 0:00:50 0:00:00 1:57:56
Speed : 30918074 Bytes/sec.
Speed : 1769.146 MegaBytes/min.
Ended : 4. juni 2018 21:32:21
Elevating to Administrator changed a lot. I will make some statistical samples tomorrow and thereby answer whether the problems is solved.
Thanks in advance
Related
Hi Robocopy Specialists,
I am not able to transfer a backup file to server using robocopy from Windows XP SP3 workstation with the following batch file:
#echo off
………..
set "LOCAL_BACKUP_PATH=H:\Backup\%LOCALDATESTAMP%"
set "REMOTE_BACKUP_PATH=X:\Backup\%REMOTEDATESTAMP%"
md "H:\Backup\%DATESTAMP%" 2 > nul
rem "%ProgramFiles%\7-Zip\7z.exe" a -tzip "%LOCAL_BACKUP_PATH%\%BACKUP_FILE%" "H:\Backup\%LOCALDATESTAMP%\Images.db" "H:\Backup\%LOCALDATESTAMP%\Images.log" >> "H:\Backup\blog.txt"
c:\robocopy\robocopy.exe "%LOCAL_BACKUP_PATH%" "%REMOTE_BACKUP_PATH%" "%BACKUP_FILE%" /COPY:DATS /w:1 >> "H:\Backup\blog.txt"
Below is the robocopy output:
----------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
----------------------------------------------------------------------------
Started : Thu Dec 29 18:00:22 2017
Source = H:\Backup\171229_1800\
Dest : X:\Backup\171229\
Files : Backup_171229180022.zip
Options : /COPY:DATS /R:1000000 /W:1
----------------------------------------------------------------------------
NOTE: NTFS Security may not be copied - Source may not be NTFS.
0 H:\Backup\171229_1800\
----------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Thu Dec 29 18:00:22 2017
This setup has worked when transferring from a Windows 7 Pro w/s to the same server where source folder is from NTFS volume (Robocopy kept adding backslash in Windows 7 batch script).
Below are differences between Windows 7 Pro setup to this one:
Workstation on Windows XP SP3 is the source folder is a FAT32 volume (H:). I have removed the S flag (from /COPY:DATS to /COPY:DAT) which eliminates the need to copy NTFS security attributes but still no backup file been transferred.
Use an alternative source folder from a NTFS volume (D:) also not able to transfer the same backup file either.
No need for compression done by vendor application backup.
Use an old C:\Robocopy\ROBOCOPY.exe as opposed to Windows 7 Pro native C:\Windows\Systems32\ROBOCOPY.EXE.
I ran out of ideas and would appreciate your expert advice.
Thanks again,
George
Robocopy displays the output correctly.
Your robocopy output says that it has not found a file with this name and that's why no file is copied.
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0
Make sure this file exists before you commit Robocopy to copy anything. Otherwise give a message in your log file that this file does not exist.
if exist "%LOCAL_BACKUP_PATH%\%BACKUP_FILE%" (
robocopy ...
) else >> "H:\Backup\blog.txt echo "%LOCAL_BACKUP_PATH%\%BACKUP_FILE%" not found.
do you know how can I use robocopy to make incremental copy ?
A simple example that I would like to have :
\\SOURCE : all files
\\DESTINATION\2016-01-01 : all files
\\DESTINATION\2016-01-02 : only all files modified or created from 2016-01-01
\\DESTINATION\2016-01-03 : only all files modified or created from 2016-01-02
etc...
Thanks for help,
Pierre
You should be able to leverage these switches:
/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).
(More switches to tailor your solution)
So to do something historical
ROBOCOPY \\Source \\DESTINATION\2016-01-01
ROBOCOPY \\Source \\DESTINATION\2016-01-02 /MINAGE:20160102 /MAXAGE:20160101
ROBOCOPY \\Source \\DESTINATION\2016-01-02 /MINAGE:20160103 /MAXAGE:20160102
If it's to take a back up for today this will suffice, on the day of backup:
Robocopy \\source \\destination /MAXAGE:1
I have a file in Wnidows/System32 that has a size of 0 bytes.
It's shown there in explorer and command prompt, bu I can't delete nor overwrite it. the system claims the file would not exist, but it stays there even after reboot.
The problem causes the installation of an app to fail because the installation also fails to overwrite the file.
I tried to delete via console,
I tried checkdisk, fileassassin, unlocker etc. all failed to delete the file.
I would be glad if anyone could help?
The system is a virtual Windows 2008 R2 server
c:\Windows\System32>dir /x msvcp*
Volume in drive C has no label.
Volume Serial Number is ECD7-BEFA
Directory of c:\Windows\System32
13.08.2014 15:17 0 msvcp100.dll
05.11.2012 23:26 661.456 msvcp110.dll
11.09.2013 19:39 614.000 MSVCP1~1.DLL msvcp110_clr0400.dll
14.07.2009 03:41 597.504 msvcp60.dll
4 File(s) 1.872.960 bytes
0 Dir(s) 93.173.768.192 bytes free
c:\Windows\System32>del /F msvcp100.dll
c:\Windows\System32\msvcp100.dll
The system cannot find the file specified.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am trying to make a backup of the files in a corrupted MySQL database before doing a clean install from a different backup file. I am on a windows 7 machine. Someone suggested the following, but the mv command does not work on windows:
mv /var/lib/mysql /var/lib/mysql.old
So instead, I am trying to use robocopy, but I am getting a range of different error messages with each attempt. Here is a screen shot of some of the error messages for my various attempts:
Here is a link to the complete suggested code in a related posting, if it helps anyone suggest the correct syntax: Click Here
I tried xcopy but am getting the following error result:
Then I tried move but got the following results, despite trying a few different ways of doing the slashes:
I added a C:\ProgramData\MySQL\bkup folder to my hard drive and tried the following:
why don't use this syntax ? :
xcopy /s SOURCEDIR DESTDIR
eg: xcopy /s C:\Users\Iman\Desktop\k C:\Users\Iman\Desktop\kk
Here's a possible approach, since the paths seem to be crossing you up:
MD C:\BackupDir
Subst G: c:\BackupDir
Cd C:\MypathtoMysql
G: (Switch to G drive)
Xcopy C:*.* /s /e
That way you're in the directory you want to copy so no need to specify it, and you're copying to a local location rather than a path location.
So, I've done this to prove what I tried to convey in the comments:
Created a directory called C:\ProgramData\directory 1\sub-directory a, and two files in it:
C:\>dir "C:\ProgramData\directory 1\sub-directory a"
Volume in drive C has no label.
Volume Serial Number is 303C-DB3D
Directory of C:\ProgramData\directory 1\sub-directory a
24/05/2014 22:35 <DIR> .
24/05/2014 22:35 <DIR> ..
24/05/2014 22:35 13 file 1
24/05/2014 22:35 13 file 2
2 File(s) 26 bytes
2 Dir(s) 1,076,169,957,376 bytes free
Created a directory C:\ProgramData\directory 2:
C:\>dir "C:\ProgramData\directory 2"
Volume in drive C has no label.
Volume Serial Number is 303C-DB3D
Directory of C:\ProgramData\directory 2
24/05/2014 22:35 <DIR> .
24/05/2014 22:35 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 1,076,169,957,376 bytes free
Used move to move sub-directory a to C:\ProgramData\directory 2 like so:
C:\>move "C:\ProgramData\directory 1\sub-directory a" "C:\ProgramData\directory 2\sub-directory a"
1 dir(s) moved.
Confirmed that the directory and its files are where they should:
C:\>dir "C:\ProgramData\directory 2\sub-directory a"
Volume in drive C has no label.
Volume Serial Number is 303C-DB3D
Directory of C:\ProgramData\directory 2\sub-directory a
24/05/2014 22:35 <DIR> .
24/05/2014 22:35 <DIR> ..
24/05/2014 22:35 13 file 1
24/05/2014 22:35 13 file 2
2 File(s) 26 bytes
2 Dir(s) 1,076,169,957,376 bytes free
In conclusion:
move can be said to be a renaming operation: The first argument, the source, is the path of the file right now, the second argument, the destination, is what you want it to be.
The parent directory of the destination should exist. E.g. if I move to C:\ProgramData\directory 2\sub-directory a there should already be a directory C:\ProgramData\directory 2.
Arguments that contain a space need to be quoted, like the directory arguments to move. Each argument should be quoted on its own.
Use relative paths when you're sure about what they should be, otherwise use absolute paths.
Is there a reason why you want this done via command line? Why not use a file-diff tool such as Beyond Compare? This tool gives you a visual overview of file differences, but can be used to copy files to another folder for backup as well. Full binary comparison of files in different folders is possible too. See a screenshot. There is a command line version included.
Perhaps this topic from SuperUser can help: https://superuser.com/questions/748069/how-do-i-compare-two-folders-recursively-and-generate-a-list-of-files-and-folder - look down the list of answers and there will be an entry on RoboCopy and its use for a somewhat similar purpose.
I would like to test for the success/failure of a copy in a batch file, but I can't find any documentation on what if any errorlevel codes are returned. For example
copy x y
if %errorlevel%. equ 1. (
echo Copy x y failed due to ...
exit /B
) else (
if %errorlevel% equ 2. (
echo Copy x y failed due to ...
exit /B
)
... etc ...
)
I'd opt for xcopy in this case since the error levels are documented (see xcopy documentation, paraphrased below):
Exit code Description
========= ===========
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred. There is not
enough memory or disk space, or you entered
an invalid drive name or invalid syntax on
the command line.
5 Disk write error occurred.
In any case, xcopy is a far more powerful solution. The equivalent documentation for copy does not document the error levels.
As an aside, you may want to rethink your use of the %errorlevel% variable. It has unexpected results, at least in some versions of Windows, if someone has explicitly done something silly like:
set errorlevel=22
In those cases, the actual variable will be used rather than grabbing the actual error level. The "normal" way of doing this is (in decreasing order since errorlevel is a "greater than or equal to" check):
if errorlevel 2 (
echo Copy x y failed due to reason 2
exit /B
)
if errorlevel 1 (
echo Copy x y failed due to reason 1
exit /B
)
In addition, if you are running Win7 or Win Server 2008 or later, you should look into Robocopy, which is now the preferred mass-copy solution.
It might also be worth pointing out that xcopy doesn't always return the error code you expect.
For example when trying to copy multiple files with a wildcard but there are no files to copy you expect a return error code of 1 ("No files were found to copy"), but it actually returns 0 ("Files were copied without error")
C:\Users\wilson>mkdir bla
C:\Users\wilson>mkdir blert
C:\Users\wilson>xcopy bla\* blert\
0 File(s) copied
C:\Users\wilson>echo %ERRORLEVEL%
0
I believe Copy only returns 0 for success or 1 for failure.
XCopy has documented return codes:
0 = Files were copied without error.
1 = No files were found to copy.
2 = The user pressed CTRL+C to terminate xcopy.
4 = Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 = Disk write error occurred.
There is also one point I would like to emphasize: xcopy as well as robocopy can only copy files, but they can't rename them.
While looking at the original situation (copy x y, which looks like a rename to me), I have the impression that the copy command still is the only one suitable for this purpose.
Error# Description
0 No error
1 Not owner
2 No such file or directory
3 Interrupted system call
4 I/O error
5 Bad file number
6 No more processes
7 Not enough core memory
8 Permission denied
9 Bad address
10 File exists
11 No such device
12 Not a directory
13 Is a directory
14 File table overflow
15 Too many open files
16 File too large
17 No space left on device
18 Directory not empty
999 Unmapped error (ABL default)