I'm trying to make a script that will become an automated backup routing that will in the end transfer folders and contents to a mapped network drive.
I'll sort of go over what I have in mind as I post what I have so far, let me know if it seems good or what your ideas are.
File paths and such are censored for privacy, blah etc.
@ECHO off
net use x: \\ipaddress\folder %1 /USER:%2 <---make mapped drive for system account, %1 variable for password to be passed on by another process to encrypt is in an executable, it's nice working with programmers. %2 variable to represent machinename\useraccount
for /d %%i in (dir c:\path\backup*) do rd "%%i" /Q /S <-- to delete old backup sub folders so I don't double up on the network drive.
c:\path\thirdpartybackupscript.bat <-- dumps backed up data to c:\path\Backup
c:\stampme.cmd "c:\path\Backup" <--working script that appends target file or folder with date & time, helpful for archiving backups.
for /d %%i in (dir c:\path\Backup*) do xcopy "%%i" r: /e <-- xcopy's over the newly created and date/time stamped folder to a mapped network drive. I'm worried if this step will run when the user isn't logged onto the server. I'd like to get that to work regardless of user login status, if I have to leave the administrative user logged in but session locked I can do that.
ForFiles /P /R:\ /D -10 /C "CMD /C if @ISDIR==TRUE echo RD /Q @FILE &RD /Q /S @FILE" <--- delete folders older than 10 days from network folder.
net use x: /delete <---delete network drive
Seem okay in theory?
Backup script that also moves stuff over network.
Moderator: DosItHelp
-
- Posts: 3
- Joined: 31 May 2012 12:42
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: Backup script that also moves stuff over network.
well most of it was syntax correct, so here is what i got:
somebatch.bat
some comments, you might want to put some logging in the bat file to let you know the status of commands (like report success or fail for 1) net use 2) rd success 3) definitely here, put success or fail)
on line 4, do you really want stampme.cmd in the root? should be moved to \somepath\ so as not to clutter up the root drive, probably want success or fail with this as well
report success or fail of line 5)
and i don't have forfiles so i will take it that your syntax is correct but again report success or fail of this and the last net use
i usually create a \LOGS file in the root and save all reports (and success or failure) to this folder for later perusal
somebatch.bat
Code: Select all
@ECHO off
net use x: \\ipaddress\folder %1 /USER:%2
for /d %%i in (c:\path\backup) do rd /Q /S "%%i"
c:\path\thirdpartybackupscript.bat
c:\stampme.cmd "c:\path\Backup"
for /d %%i in (c:\path\Backup) do xcopy "%%i" r: /e
ForFiles /P /R:\ /D -10 /C "CMD /C if @ISDIR==TRUE echo RD /Q @FILE &RD /Q /S @FILE"
net use x: /delete
some comments, you might want to put some logging in the bat file to let you know the status of commands (like report success or fail for 1) net use 2) rd success 3) definitely here, put success or fail)
on line 4, do you really want stampme.cmd in the root? should be moved to \somepath\ so as not to clutter up the root drive, probably want success or fail with this as well
report success or fail of line 5)
and i don't have forfiles so i will take it that your syntax is correct but again report success or fail of this and the last net use
i usually create a \LOGS file in the root and save all reports (and success or failure) to this folder for later perusal
Re: Backup script that also moves stuff over network.
Having generations of backups is wise - in case you changed something and have backed it up - and only then realise you need the old version.
My other comment is that ROBOCOPY.EXE is a great backup utility.
My other comment is that ROBOCOPY.EXE is a great backup utility.
-
- Posts: 3
- Joined: 31 May 2012 12:42
Re: Backup script that also moves stuff over network.
Something I'm having trouble with so far is that when the backup folder is time stamped, I need to be able to move the folder, keeping that time stamped name, and it's entire contents, to the network drive. The closest I've come so far with xcopy is taking the contents of the time stamped folder and moving them over, which is really close, but I need that original named folder for versioning. I'm not sure, but does robocopy allow you to copy a folder using a wildcard at the end? Basically it needs to be able to look for backup* so backup as the prefix, then the time stamp after that.
Re: Backup script that also moves stuff over network.
This should give you a list of each folder in a loop
Code: Select all
@echo off
pushd "c:\backup folder"
for /f "delims=" %%a in ('dir backup* /ad /b') do (
echo "%%a"
echo "%%~nxa" when /s is not used in the dir command then this will be the same as the one above
echo "%%~dpa"
)
popd