Drive on, Backup, Drive offline via batch file

721 views Asked by At

I try to write a batch file which:

  1. Set one drive online
  2. Backup files
  3. Set drive back offline

I have a batch file that sets the drive online, one file taking it offline and a batch file that robocopys the files I want.

BUT

  1. I dont get them together. I have now three files and have to wait for one getting done to start the next one.
  2. robocopy isnt done til the drive is set offline again. I dont know how I get the offline command waiting for robocopy to be done.

File for drive online (.bat):

diskpart /s C:\Users\USERNAME\Desktop\FestplatteDiskpartON.txt
list disk
select disk 1
online disk
diskpart > exit

File for copy (.bat) / file :

robocopy D:\Tastaturen\ E:\ /MIR

File for drive offline (.bat):

diskpart /s C:\Users\USERNAME\Desktop\FestplatteDiskpartOFF.txt
"C:\Program Files\HDDScan\HDDScan.exe" "\\?\scsi#disk&ven_&prod_st2000dm008-2fr1#4&39693902&0&020000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" -APM 1 -PM 0 -Z
list disk
select disk 1
offline disk

I tried:

@ echo off
start /wait "" "C:\Users\USERNAME\Desktop\Festplatte online.bat"

:: Start BackupVorgang
start /wait "" "robocopy D:\Tastaturen\ E:\ /MIR"

diskpart /s C:\Users\USERNAME\Desktop\FestplatteDiskpartOFF.txt
"C:\Program Files\HDDScan\HDDScan.exe" "\\?\scsi#disk&ven_&prod_st2000dm008-2fr1#4&39693902&0&020000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" -APM 1 -PM 0 -Z

echo done

In this szenario backup doesnt work. "Cant find robocopy".

I also tried with timeout /x after setting online.

I dont know how I can get the batch file setting the drive online, THAN copy, wait for the copying done and than set the drive offline.

1

There are 1 answers

0
John Smith On
@ECHO OFF
@CLS
(
echo List Disk
echo select disk 1
echo online disk
echo exit
) > script.txt
diskpart /s script.txt
robocopy robocopy D:\Tastaturen\ E:\ /MIR
echo End backup time: %DATE% %TIME%
DEL script.txt
(
echo List Disk
echo select disk 1
echo offline disk
echo exit
) > off.txt
diskpart /s off.txt
DEL off.txt