Today I was asked to come up with a script that could do the following:
check three directories on the D:\ for files older than 30 days
If there are files on there older than 30 days then move them to E:\ using the exact directory structure (this is to backup old log files to retain disc space)
We need to have a log running which would record the date, time, log name and then if the move files fails to raise an event in the event viewer or send an email to notify of error.
Now I know I will get treated like a noob, I have created some scripts to get this working by doing each step first and then trying to add them together, this always seems to fail.
Use robocopy in a batch file for this kind of task:
#echo off
robocopy D:\ E:\ /mov /s /minage:30
Don't waste your time on trying to re-invent robocopy in VBScript.
Related
I am looking for a way to copy new files only from a folder to another one. The criteria are:
No PowerShell.
No software, just batch shell.
Timestamp in milliseconds or seconds, not minutes.
No sync. Files on folder B can be deleted, I only need new files from folder A to by copied.
Workflow:
Watch folder A.
New file written, copy to folder B.
I have tried with xcopy and robocopy but as far as I understand, using the timestamp in both is in days while I want to compare the timestamp in milliseconds.
XCOPY
/D:mm-dd-yyyy
Copy files changed on or after the specified date.
If no date is given, copy only files whose
source date/time is newer than the destination time.
ROBOCOPY
/minage:<n> Specifies the minimum file age (exclude files newer than n days or date).
The ideal solution I have in mind (forgive my ignorance here as I am not a windows user):
#REM new_only.bat
CURRENT_TIME=%date%%time%
SOURCE_DIR="c:\source"
TARGET_DIR="c:\target"
:start
xcopy %SOURCE_DIR% %TARGET_DIR% /time>%CURRENT_TIME%
goto start
Hello not sure where I should place this question but;
I want to run a batch script on a windows machine every night around midnight.
All I want it to do is back up all files and folders on a network drive and copy this to a hard drive on the computer running the batch script. The only thing unsual I want it do is exclude copyying a folder called trashbox
Local Computer
C:\BACKUP\
Network Drive
Z:\FILES\*
exclude Z:\FILES\trashbox
So it needs to;
Remove previous days backup
Start at midnight
Backup all files and folders on Z:\FILES*
Exclude Z:\FILES\trashbox* from copying
Any ideas would be most appreciated!!
Test this: it will create a mirror backup and delete files that aren't needed but keep files that already exist, and only copy the different files.
robocopy "Z:\FILES" "C:\BACKUP" /mir /xd "trashbox"
Create new batch file using below code. It will first remove the previous directory and create new one after that copy all content to new dir from network drive.
rmdir /s /q "C:\Backup"
TIMEOUT 5
mkdir "C:\Backup"
copy /y "Z:\Networkfolder" "C:\Backup"
TIMEOUT 5
rmdir /s /q "C:\Backup\trashbox"
exit
i need to a .bat file to copy with xcopy command the files from a specific directory that are 90 days new. that means to take the todays date and take out 90 days of it and do not perform the copy.
help is needed,
thx
Use ROBOCOPY not XCOPY. It will do what you want very easily. Robocopy is installed on Windows 7 and is a free download for other versions.
ROBOCOPY /S /MAXAGE:90 P:\path\to\source Q:\path\to\dest
There are many other options, for minimum age, min and max size, attrributes, filtering by file and directory names, and so forth.
Also you can use the /L option to just list what it would have done, to check you have the other options right.
Is it possible to create a DOS script that will move 2000 files to another folder every 10 minutes?
For example:
C:\MyFolder\
Every 10 minutes move 2000 files to C:\MyNewFolder\
Thank you!
I would use something like xcopy as recommended, however I would use the date flag to specify only copying new files. Just omit the date and it will copy only newer files.
/C Continues copying even if errors occur.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/E Copies directories and subdirectories, including empty ones.
xcopy C:\Source Z:\Destination /C /D /E
Use Schtasks.
You may want to look here: http://technet.microsoft.com/en-us/library/bb490996.aspx
I'm trying to create a script that will automatically backup a complete directory tree. I also want it to work for incremental backups. Basically, it wil work like this:
If file is in both source and destination and they are different, source file will be copied
If file is in both source and destination and they are the same, nothing will be copied
If file is only in the source, source file will be copied
If file is only in the destination, destination file will be deleted.
I'm still new to shell scripting and I'm not sure how I could implement this. Any ideas? Windows batch scripts would be better, but shell scripts that run on Cygwin are also fine.
Take a look at rsync tool - it was designed to minimize traffic during files synchronization.
Also, probably "cp" with "-u" argument will be useful:
-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is missing
For windows batch scripting xcopy (native to windows) or robocopy (a free download in windows) both work extremely well.
An example xcopy script (in a .bat file):
#echo off
:: /L = list only.
:: /v=Verify, /y=No prompting /s=subdirs /z=Network mode (supports bad)
:: /i=Tells xcopy dest is folder /f=Display names /d=Copy only changed
echo Backing up projects...
xcopy e:\projects h:\projects /V /Y /S /Z /I /F /D
It will even support orphaned files (if you delete something from your source you no longer need a copy in the backup). Xcopy is typically fine for your needs until you deal with sync between NTFS and Fat32 file systems - the later only has a 2 second resolution and problems with daily savings time so you occasionally run into issues: (a) on time change day you might not get a backup of a changed file - depends on change-regularity of course or you might get a backup of all files even though none have changed (b) because of time resolution some files may backup even though they haven't changed.