Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
scienceguru1.bat
- Posts: 44
- Joined: 01 Jan 2011 20:54
#1
Post
by scienceguru1.bat » 27 Aug 2011 20:12
I am trying to make a batch script that will UPDATE the folder assigned to the computer. The folder is Z:\Data\Backups\(Computer) . If I use robocopy /mir will it delete files that were deleted on the computer?
So far:
Code: Select all
@echo off
echo Updating backup of files on Time Capsule...
robocopy /mir
echo Done!
echo Press any key to exit.
pause>nul
Also, is there a way to:
a) display the status of the robocopy
b) only delete files that are gone from the computer that are over 2 1/2 months old?
Thanks, sg1.bat
-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#2
Post
by Ranguna173 » 28 Aug 2011 17:14
Well...
Showing the progress..
Easy but it'll take a long time to write.
Lets say that you have a directory:
C:\backup\
Inside the "backup" folder there are 10 files:
C:\backup\1
C:\backup\2
C:\backup\3
C:\backup\4
C:\backup\5
C:\backup\6
C:\backup\7
C:\backup\8
C:\backup\9
C:\backup\10
You have inserted a Pen drive (H:\)
The batch would be:
Code: Select all
@echo off
cd H:\
if exist backup_of_a_backup (
goto start
) else (
md backup_of_a_backup
goto start
)
:start
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 0%
cd C:\backup
copy 1 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 10%
copy 2 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 20%
copy 3 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 30%
copy 4 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 40%
copy 5 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 50%
copy 6 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 60%
copy 7 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 70%
copy 8 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 80%
copy 9 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 90%
copy 10 H:\backup_of_a_backup
cls
echo Copying files from "C:\backup" to "H:\backup_of_a_backup"
echo 100%
echo.
echo The backup has been done!
pause>nul
exit
But There is another easier way to do this..
That is the hardest i think..
-
scienceguru1.bat
- Posts: 44
- Joined: 01 Jan 2011 20:54
#3
Post
by scienceguru1.bat » 28 Aug 2011 19:11
If it helps any, I am backing up the C:\Users folder to our Apple Time Capsule, which the correct folder to backup to is going to be Map Network Drived to B. I want two backups.
New Code:
Code: Select all
@echo off
echo Back up C:\Users to B:\
echo ...
echo ...
echo ...
echo Replacing oldest backup...
robocopy B:\newer B:\older /mir
echo Creating new backup...
robocopy C:\Users B:\newer /mir
echo Done!
echo Press any key to exit...
pause>nul
-
Ocalabob
- Posts: 79
- Joined: 24 Dec 2010 12:16
- Location: Micanopy Florida
#4
Post
by Ocalabob » 28 Aug 2011 21:45
Greetings Sg1.bat,
This is more of a Robocopy question than batch file one; my quick comments:
-Robocopy has a very detailed help file.
-The switch /mir will 'mirror' your 'source' to the 'destination'
and delete files that no longer exist on the 'source' including
sub-folders. There are better combinations of switches to use than /mir.
-To record results look at switches /log+:file and /tee
-You can also run Robocopy and check the 'source' for changes,
and back the changes up to the 'destination' as they occur.
Post back if you need help with your batch file.
Best wishes Sg1.bat