[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

script for folder movement on same partition

I'm running Veritas, and backing up the exchange database to disk, on a 5 day rotation.
monday
tuesday
etc
Each of these folders has multiple IMG****  folders, 2 are created everyday, one for each store.   I need to grab the most recent 2, and move them to another folder, on the same drive NOT COPY so I can then backup those 2 folders along with the OS backup2disk data.  Last step would be to move the two folders back, script that runs at end of veritas job  They have to go back, because Veritias needs to overwrite the oldest folders to actively manage the directory size, rolling.

GRT disk management didn't work in 11d, but its works great in 12.5  ( grt append function to disk backups)

I've played with the for command in other areas, but I can't ferret out how to grab via folder date

If?  FOR?  VBS something???
0
Plysaker
Asked:
Plysaker
  • 8
  • 8
1 Solution
 
AmazingTechCommented:
Try this out. Remove the ECHO infront of MOVE to actually have it move the folder.

To move it back you should be able to move all folders from C:\OSBackup

for /f %%a in ('dir /ad /o-d C:\OSbackup\IMG*') do ECHO MOVE "c:\OSbackup\%%a" "c:\Backup\%%a"
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set GetFirstXFolders=2
for /f %%a in ('dir /ad /o-d C:\backup\IMG*') do if !GetFirstXFolder! NEQ 0 ECHO MOVE "c:\backup\%%a" "c:\OSBackup\%%a" & Set /a GetFirstXFolder-=1

Open in new window

0
 
PlysakerAuthor Commented:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set GetFirstXFolders=2
for /f %%a in ('dir /ad /o-d v:\backup2disk\monday\IMG*') do if !GetFirstXFolder! NEQ 0 MOVE "v:\backup2disk\monday\%%a" "v:\2tape\%%a" & Set /a GetFirstXFolder-=1
 
4 different batch files, M-Th  folder structure is in attached jpeg.  I just need to 2 most recent IMG* folders in each DIR moved to temp folder "2Tape"  
 
I then grab the OS disk back up and whats in the 2tape backup, with a veritas job to tape.  10 tape mag loader.
 
my modifed line didnt do sheet.



folders.jpg
0
 
AmazingTechCommented:
Opps.

The variable name is wrong.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set GetFirstXFolders=2
for /f %%a in ('dir /ad /o-d v:\backup2disk\monday\IMG*') do if !GetFirstXFolders! NEQ 0 MOVE "v:\backup2disk\monday\%%a" "v:\2tape\%%a" & Set /a GetFirstXFolders-=1

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PlysakerAuthor Commented:
I put the echo back in:  Where is the If picking up "volume" ?

V:\backup2disk>test
MOVE "v:\backup2disk\monday\Volume" "v:\2tape\Volume"
MOVE "v:\backup2disk\monday\Volume" "v:\2tape\Volume"
0
 
AmazingTechCommented:
Opps sorry in the Volume is in DIR

dir

should be /b for basic so it only should the names of the files.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set GetFirstXFolders=2
for /f %%a in ('dir /b /ad /o-d v:\backup2disk\monday\IMG*') do if !GetFirstXFolders! NEQ 0 MOVE "v:\backup2disk\monday\%%a" "v:\2tape\%%a" & Set /a GetFirstXFolders-=1

Open in new window

0
 
PlysakerAuthor Commented:
can you break this down for me so I can understand it?  I got the first if, but the second, with the variable blows my mind...
0
 
PlysakerAuthor Commented:
for /f %%a in ('dir /b /ad /o-d v:\backup2disk\2tape\IMG*') do ECHO MOVE "v:\backup2disk\
2tape\%%a" "v:\backup2disk\monday\%%a"

Results:

%%a was unexpected at this time
0
 
AmazingTechCommented:
From the command line you need just 1 %

for /f %a in ('dir /b /ad /o-d v:\backup2disk\2tape\IMG*') do ECHO MOVE "v:\backup2disk\
2tape\%a" "v:\backup2disk\monday\%a"
0
 
PlysakerAuthor Commented:
do was unexpected at this time.
0
 
PlysakerAuthor Commented:
for /f %a in ('dir /b /ad /o-d v:\backup2disk\2tape\IMG*') do MOVE "v:\backup2disk\2tape\\a" "v:\backup2disk\monday\%a"
0
 
AmazingTechCommented:
Do should be OK.

Cut and paste in to command line should echo MOVE with all IMG folders
for /f %a in ('dir /b /ad /o-d "v:\backup2disk\2tape\IMG*"') do ECHO MOVE "v:\backup2disk\2tape\%a" "v:\backup2disk\monday\%a"

Open in new window

0
 
PlysakerAuthor Commented:
when I copy paste this string in CL it works, when its in a .BAT and echo removed and ran, it fails with syntax error.

WTF?
0
 
AmazingTechCommented:
In a batch file you need 2 % for the variables.
for /f %%a in ('dir /b /ad /o-d "v:\backup2disk\2tape\IMG*"') do ECHO MOVE "v:\backup2disk\2tape\%%a" "v:\backup2disk\monday\%%a" 

Open in new window

0
 
AmazingTechCommented:
If the above worked then try it with the 2 most recent IMG folders.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Set GetFirstXFolders=2
for /f %%a in ('dir /b /ad /o-d "v:\backup2disk\2tape\IMG*"') do if !GetFirstXFolders! NEQ 0 Echo MOVE "v:\backup2disk\2tape\%%a" "v:\backup2disk\monday\%%a" & Set /a GetFirstXFolders-=1

Open in new window

0
 
AmazingTechCommented:
Oh. If your using notepad to save this batch file make sure the encoding is ANSI.
0
 
PlysakerAuthor Commented:
excellent, thanks again EE!
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now