Skip to main content

How to automatically connect and disconnect an external hard drive before and after a backup

Thread needs solution
Beginner
Posts: 2
Comments: 10

My ATI2017 makes a weekly backup of my entire system (1 full backup and 5 times an incremental backup and this is repeated every 6 weeks). Is it possible via Option > Advanced settings to program via the Pre- and Postcommands to automaticcally connect (or mount) my external hard drive before the actual backup starts and to disconnect (or unmount) my external hard drive after the backup has been made. So physically I do not want to unplug my external hard drive but the drive is logiccally ejected but not unplugged. In this way I hope that possible ransomware cannot effect my external hard drive, because it is not connected. If this is possible which commands should I use?

kind regards

Herman Vroomen

0 Users found this helpful
Legend
Posts: 102
Comments: 22850

#1

Herman, from my limited understanding of mounting / unmounting external USB drives, you would most probably need to use some third party utility / program / software to be able to do this, but as protection from ransomware, then if you can mount / unmount a drive via coding, then the malware authors could do the same to find connected but unmounted drives!

If you wanted a more secure way of doing this, and assuming that your external drive has its own separate power supply (not being powered via the USB port), then you could simply put a timer switch in the circuit for the external drive and time the drive to be powered on a couple of minutes before your scheduled backup runs and then to power it off again after a suitable delay to allow time for the backup to finish.

Legend
Posts: 102
Comments: 22850

#2

Please see webpage: 5 Ways to Remount Ejected or Safely Removed USB Device Without Unplug and Reinsert  that I found in my browser bookmarks from dealing with a previous question in this area.

Beginner
Posts: 2
Comments: 10

#3

Dear Steve

thank you very much for your reply. Your first suggestion is not possible in my case because my external hard drive does not have its own power supply that can be switched off and on by a timer switch.

your second suggestions especially number 4 might be an option because it can be fully automated without having to manually click anything i.o.t. disconnect or connect my hard drive. I hope it works on my W10 pc by putting the commands in a batch file to connect the USB device and one in another batch to disconnect the USB device and start them by inserting them in the advanced settings of ATI 2017 pre- and post commands options. I will try it an let you know the result. Thank you.

Beginner
Posts: 2
Comments: 10

#4

Dear Steve or others,

using the suggestions in the webpage https://www.raymond.cc/blog/remount-ejected-or-safely-removed-usb-devic… I did not succeed to "rescan" the usb disk in order to reconnect it again or  "remove" the usb device in order to eject the usb disk. I installed the devcon.exe in C:\devcon\ and used the following pre-command in the advanced settings in ATI 2017:

c:\devcon\devcon.exe rescan

it did not reconnect the plugged-in usb disk

And I used the following post-command to eject the usb disk

c:\devcon\devcon.exe remove *VID_174C*

*VID_174C* is my hardware-Id of the Usb diskdrive according my Device Manager. it did not eject or remove my disk

i hope you or somebody else have maybe an alternative suggestion to reconnect and eject my usb drive using commands in the pre- and post-commands section of ATI2017.

Thank you

Legend
Posts: 102
Comments: 22850

#5

Herman, did you try this just by using the Pre & Post Commands or did you test these commands separately outside of ATI ?

Beginner
Posts: 2
Comments: 10

#6

I tried first the pre- and postcommands in a normal DOS-prompt window which did not work, however when I executed the Prompt as an administrator I could eject the drive via the devcon "remove" command and I could connect it again via the devcon "rescan" command.

then I used the pre- and postcommands in ATI, but there it did not work as hoped for. Actually at some point I had to restart my pc and unplug and plug in my usb drive to get my ext. drive back again connected.

I also tried to run ATI as an administrator but that did not help.

Legend
Posts: 102
Comments: 22850

#7

Herman, ATI should always be run as Administrator in order to have the correct privileges but there are known issues with getting the Pre Post Commands to run correctly when administrator privileges are needed.

Have you tried setting the devcon.exe program to always run as administrator via the compatibility settings?

Legend
Posts: 102
Comments: 22850

#8

Hermon, I look to have been able to get this working with one of my own removable USB drives (powered via USB) by creating two small VBS script programs.

RescanUSBdisk.vbs

Dim oShell

Set oShell = CreateObject("WScript.Shell")
oShell.Run "H:\devcon.exe rescan" , 0, True
Wscript.Sleep 10*1000
WScript.quit

RemoveUSBdisk.vbs

Dim oShell

Set oShell = CreateObject("WScript.Shell")
oShell.Run "H:\devcon.exe remove *VID_14CD*" , 0, True

WScript.quit

The sleep time (10 seconds) delay after the rescan is to allow for any devices found to be reconnected.

The log for my backup task showed:

Backup reserve copy attributes: format tib; need_reserve_backup_copy false;
Operation TestPrePostVBS started manually.
Backup reserve copy attributes: format tib; need_reserve_backup_copy false;
Operation: Backup
Priority changed to Low.
Child process has exited with code '0'.
Execution of user command succeeded: E:/Dropbox/Acronis/Scripts/RescanUSBdisk.vbs
Create Backup Archive From: E:\Dropbox\Acronis\
To file: TestPrePostVBS_inc_b1_s5_v1.tib Compression: Normal 
Writing incremental version to file: TestPrePostVBS_inc_b1_s5_v1.tib
The following backups have been successfully created: L:\TestPrePostVBS_inc_b1_s5_v1.tib
Child process has exited with code '0'.
Execution of user command succeeded: E:/Dropbox/Acronis/Scripts/RemoveUSBdisk.vbs
Operation has succeeded.

Legend
Posts: 102
Comments: 22850

#9

Herman, after playing with the above vbs scripts a little more I found that although the USB drive didn't show in the Safely remove hardware dialogue list, it was still showing in Windows Explorer so needed some further actions.

The revised scripts are as follows:

RescanUSBdisk.vbs

Dim oShell

intTimeout = 5      'Number of seconds to wait
strMessage = "USB disk devices scanned & drive mounted as L:"
strTitle = "RescanUSBdisk"

Set oShell = CreateObject("WScript.Shell")
oShell.Run "H:\devcon.exe rescan" , 0, True

oShell.Run "mountvol L: \\?\Volume{18000000-0000-0000-0000-100000000000}\"

intResult = oShell.Popup(strMessage, intTimeout, strTitle)
Wscript.Sleep 10*1000

WScript.quit

RemoveUSBdisk.vbs

Dim oShell

intTimeout = 5      'Number of seconds to wait
strMessage = "USB disk devices removed"
strTitle = "RemoveUSBdisk"

Set oShell = CreateObject("WScript.Shell")
oShell.Run "H:\devcon.exe remove *VID_14CD*" , 0, True

intResult = oShell.Popup(strMessage, intTimeout, strTitle)
oShell.Run "mountvol L: /d"
Wscript.Sleep 10*1000

WScript.quit

Note: you will need to find the GUID for your USB disk by connecting it, then in a Command window, issue the command Mountvol /?  then copy the \\?\Volume{180...  detail to your script file, plus also give the correct drive letter for the Mounvol commands to dismount / remount the drive letter.

I have been able to test the above scripts as Pre/Post Commands successfully, with the drive being disconnected (as in not shown in Explorer or to Acronis) as the script is started, then successfully connecting the drive to run the backup before disconnecting (unmounting the drive letter) again on completion.

Beginner
Posts: 2
Comments: 10

#10

Dear Steve,

Thank you very much for all the effort you have put in solving my problem. I am going to test it right now and let you know asap.

Beginner
Posts: 2
Comments: 10

#11

Dear Steve,

It Works !!!!!!! (After correcting a typing error (a few zeroes too many) that I made in the RescanUSBdisk.vbs ) Which took a while before I found it.

I have tested it today by starting 5 backup cycles, and every time it disconnected my USBdisk at the end of each backup and reconnected it at the beginning of a backup.

Thank you very much. A great job.

Forum Star
Posts: 146
Comments: 1254

#12

Steve, nice job! I don't need this, but I will keep it handy just in case I find a future need.

This brings up two suggestions:
1. Use command line parameters for drive letter, volume, etc.
2. How about a repository for scripts like this which can be made available, either through MVP tools or through Acronis if they'd be game. The flexibility of ATI could be well enhanced as people solve problems through add-on scripting.

Legend
Posts: 102
Comments: 22850

#13

Herman, glad to be able to help with this request - has been very much a learning exercise for me to keep the 'little grey cells' busy for a while longer!

Bruno, I will make a write up of how these vbs scripts will need to be used and post it to the MVP User Tools folder on Google Drive in the MVP User Guides and How To's folder.

My vbs coding skills are elementary to say the least - this was my first venture other than having coded vb scripts within Excel some years back!

Legend
Posts: 102
Comments: 22850

#14

Herman, Bruno, please would you review the document Auto connect disconnect USB drive.PDF before I post it to the MVP Google Drive folder.

I have made some further changes in line with Bruno's comments to use command line parameters, so that all changes are made near the top of each script.

Example:

strDrive = "L:" 'Change to the drive letter for the USB drive
strGUID = "\\?\Volume{18000000-0000-0000-0000-100000000000}\"  'Change to the GUID of the drive
strCmd = "H:\devcon.exe"  'Change to the path where DEVCON.EXE is found.
 

Forum Star
Posts: 146
Comments: 1254

#15

Steve, I've back channeled some code to you to handle parameter passing. I think it would make the scripts far easier to use.

Legend
Posts: 102
Comments: 22850

#16

Bruno, thanks for the PM, have replied likewise.  

In reply to by Steve Smith

Beginner
Posts: 2
Comments: 10

#17

Dear Steve,

My comments and a few observations:

I have modified my scripts according to your suggestions in your document and tested it 2x on my system. It works fiine. The USBdrive connects at the beginning and disconnects at te end of the backup.

Your documents is clearly described.

Is it maybe useful to describe here as well how to set that Devcon.exe and TrueImage.exe are always executed as administrator via the compatibilty properties settings?

Further I noticed that a power down and power up or a restart cycle of my pc did not reconnect my USBdisk again, which for me is perfect, because this USBdisk is only meant for ATI backup purposes, that is scheduled once a week. So during that week the USBdisk is not easy accessable by other programms (or Ransomware, I hope). 

Only now and then when I need to remove old .tib files to free up disk space, I would like to make the disk visible and accessable again in the Windows Explorer. Just unplugging and replugging the USBdisk did not work in my case. When the USBdisk is plugged in, the hardware safe remove icon is visible in the system tray, but no drive letter is shown for the USBdisk. When unplugged, the icon disappears. So via a reboot or by reinserting the USBdisk, I can not make the disk accessable via the Windows Explorer.

Only when I run the RescanUSBdisk.vbs script in an Adminstrator Command Window, the USBdisk becomes visible again in the Windows Explorer. Also the drive letter and diskname becomes visible in the Hardware Safe Remove icon in the system tray.

Are above observations normal? I can live with it. Although just unplugging and reinserting again the USBdisk to make it visible and accessable again in Windows Explorer would be easier and quicker.

Regards

Herman Vroomen

Maastricht, The Netherlands

Forum Star
Posts: 146
Comments: 1254

#18

Herman, to turn the device on and off quickly I would suggest creating a couple batch files that will call the vb scripts. Then, put shortcuts on your desktop or start menu to run them with a simple click. You can go to the Properties for a shortcut and select to run as administrator.

In reply to by BrunoC

Beginner
Posts: 2
Comments: 10

#19

Dear Bruno,

Thanks for your suggestion. The shortcuts to the .bat files on my desktop work fine. But how do I get them on my start menu?

regards Herman

Forum Star
Posts: 146
Comments: 1254

#20

Herman, just move the shortcut to C:\ProgramData\Microsoft\Windows\Start Menu (to make it available to all users), or to your C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu (for your user only). Once it is there, you can pin it if you'd like.

I'm assuming Windows 10.

Legend
Posts: 102
Comments: 22850

#21

Herman, I have looked at this topic further and have simplified the vbs script to still do the same thing but without the need for using devcon.exe, just using the mountvol command present in Windows.  I have also removed the need to find the long drive volume GUID and modify the scripts for this or the drive letter.

Please see the updated PDF document: Auto connect disconnect USB drive plus a zip file with the new vbs scripts: AutoMountRemoveUSBDrive.zip

I have added a new GetMountvol.vbs script which will prompt for your USB drive letter and use this to find the GUID needed for the other scripts via a small text file it creates in the same folder as the scripts.

Beginner
Posts: 2
Comments: 10

#22

Dear Steve, I have installed the new .vbs scripts as provided by you in the zip-file and they work fine as pre- and post commands in ATI2017. Great job! Thank you.

Legend
Posts: 102
Comments: 22850

#23

Herman, glad that the new scripts worked ok for you (as they did in my own testing) - I will post these to the MVP User Tools repository on Google Drive.

Legend
Posts: 102
Comments: 22850

#24

Document and VBS script zip file now both stored on MVP User Tools and Tutorials repository on Google Drive in the MVP User Guides and How To's folder with file names:

AutoMountRemoveUSBDrive.PDF / .ZIP

Beginner
Posts: 2
Comments: 2

#25

Hi, Steve Smith:

Before anything, sorry for my english. I am using a Google Translator, my language is spanish.

I know that your last, very, very usefull post was last year and I want to thank you for the change of download the .PDF file and the zip files you posted on MVP User Tools and Tutorials.

I don't use Acronis, I use a program called SyncBackFree in its free option, like the name say and do the job for me without any problem. Even has the options of Post-Command and Pre-Command and yours scripts work fine if I run then As Administrator from Administrator Command Prompt. When the scripts run inside the program they do but not as Administrador and all the purpose of the idea fail.

¿Did you know is there a way of make this script run as administrator inside the program?

I don't know much about scripts but may be writing at the beginnig something like Runas?

Don't know. Can you help me please!

Julio

Legend
Posts: 102
Comments: 22850

#26

Julio, I would recommend trying the following first:

Open the Properties for your SyncBackFree program (right-click then select Properties).

Open the Compatibility tab settings in the Properties window.

Click on the button to "Change settings for all users"

In the new windows, click to "Run this program as administrator" then click OK to save.

2018-12-10 SyncBackFree admin.png

Beginner
Posts: 2
Comments: 2

#27

Steve, thanks a lot for your answer. I will try your suggestion and I think probabbly will work, because I was looking in a friend's computer, who has Acronis installed and every time Acronis star to run looks like it's doing with elevated rights, since Windows always shows the UAC window.

 

Very thankful, Julio

Beginner
Posts: 0
Comments: 2

#28

Steve,

I hate to revive an old thread but I'm running into some trouble.

Thanks for those .vbs scripts, I've been using them for several years on an old Win7 box with no issues.  I recently upgraded that machine to Win10 and ATI2021 and am running into an 'administrator' issue myself.  If I run them from an elevated command line, they work great.  If I run them from within ATI2021, they fail now.  They also won't run if I double-click on them from within Explorer.  I added the 'Run As Administrator' registry key for .vbs files and that didn't do much from Explorer.  

I also added 'Run As Administrator' to all the ATI .exe files...no dice.  There's a chance I'm missing one, though, as I have ATI set to start with the computer as a service...I'm really not sure which .exe needs to run as admin.

I created batch files for the remove/add process, then created shortcuts, then set those to run as admin...that didn't work either.

Basically, the only thing that works right now is to run them from an elevated command prompt.

Are these still working for you in 2020 and, if how, how'd you get it working?

Thanks much, I appreciate your efforts!
 

Legend
Posts: 102
Comments: 22850

#29

Brian, I haven't used any of the .vbs files for this topic for a long time but migrated the functions to use Powershell instead.

I just tested the .ps1 (Powershell scripts) on one of my backup tasks for ATI 2021 and these work fine for me, although the initial USB mount isn't recognised immediately by ATI and it does an error retry per the Options > Error handling settings and happily continues the backup then removes the USB drive letter.

There are 3 Powershell scripts being used along with 3 Windows batch files (.BAT).

  1. getMountvol.ps1 - creates a small text file with the volid information required by the other two scripts so has to be run first.
  2. MountUSBdisk.ps1 - mounts the USB drive identifed by the volid text file.
  3. RemoveUSBdisk.ps1 - removes the USB drive letter again per the volid text file.
  4. MountUSBdisk.bat - launches the Pre Command powershell script
  5. RemoveUSBdisk.bat - launches the Post Command powershell script
  6. getMountvol.bat - used to run the powershell script to create the volid text file.

There are some changes that will be needed for the .BAT files as these are set to where I keep the powershell scripts on my PC (D:\Powershell\USB_Mount), which you will need to set to your own file store location.

The getMountvol.ps1 script accepts a drive letter parameter or else defaults to my drive S: USB drive, this can be set in the getMountvol.bat file in the set drive="F:" line (set for your drive letter).

Hopefully the above will make sense to you along with the attached zip file containing the scripts.

Just put the Mount / Remove .bat files in the Pre & Post command options once the mountvol.txt file has been created via getMountvol.

Attachment Size
556898-206397.zip 2.53 KB
Legend
Posts: 102
Comments: 22850

#30

Brian, further to my post above, I have been able to reduce this down to a single Powershell script and associated batch file for launching it.

The single script is CheckUSBdisk.ps1 with CheckUSBdisk.bat to launch it and pass 2 parameters, one in the .bat file and the other in the Pre / Post Command to tell the script what action to perform (Remove or Mount).

New zip file attached.  Updated zip attached in later post.

Usage as shown in the image below:
Change the store location for the script & batch files to suit your PC.

Legend
Posts: 102
Comments: 22850

#31

Documented the new CheckUSBdisk scripts with a new PDF document added to the zip file attached below.

Updated zip file attached in later post (to correct a logic error in script)

Beginner
Posts: 0
Comments: 2

#32

Legend...you're the best, man.  Works like a charm.  I appreciate the work you've done on these, it's an underrated setup to (maybe) prevent malware from wiping a connected drive.  Thanks again, I owe you a beer or beverage of your choice! :)

Legend
Posts: 102
Comments: 22850

#33

Brian, there are 2 mistakes in my Powershell script where I have used '=' when I should have used '-eq' in the script.

The 2 lines (line 16 and 21), should read:

if ($action -eq "Mount"  or if ($action -eq "Remove" otherwise the if statement isn't doing what it should do correctly!

Corrected script in the updated zip file attached to later post.

Forum Star
Posts: 146
Comments: 1254

#34

Steve, just took a look-see at your zip.

Your PDF file has the commands backwards... it shows Mount on the post-command and Remove on the pre-command.

Legend
Posts: 102
Comments: 22850

#35

Bruno, late nights = senior moments!  Simple correction in the PDF to rename Post to Pre and the reverse! 

Updated / correct scripts attached!

Attachment Size
557182-206539.zip 199.3 KB