nicolasgaillard:
Hi, I am using an external HDD for backup and I would like to make it connectable.
The idea is to use an Arduino with a relay module to switch on/off the USB cable. This way I don't have to do it manually.
If am I right, there are 4 wires in USB cable, so I should connect the power one to the relay ?
May I mess up the HDD this way ?
I back up my entire system to a USB hard drive each Sunday night. Sometimes I forget to plug it in, also.
The USB cable has 4 wires, as you suspect. Ground, 5 volt power and two data wires.
I don't see how you can mess up the hard drive that way, but you may mess up the data transfer and the USB initial protocol because of changes to the resistance/capacitance of the data wires. Be sure you have a second cable!
The 5 volt power wire should be the only connection the relay needs to control.
How will you know the Arduino has connected the disk to the PC?
Normally, a USB storage device, say with a FA32 file system, has to be cleanly "ejected", otherwise their is a theoretical risk that the data may be corrupted. In practice, I have no idea how great the risk is, though
I am going to use an ESP8266 so I can communicate with it using WIFI
For the cleanly ejection, I will unmount (linux) the device and then request the Arduino to shutdown the relay.
What is the purpose, incidentally ? To save electricity or to make the device unreachable from the device it is attached to for security reasons etc. or what ?
It is more a POC than a serious feature. It is about security, I think it is a good idea for protecting data against ransomware.
I will test it when I will receive the relay.
And no it's no the XY problem, I am not asking how to protect m'y data but I am asking if the 5v wire inside the cable is the good one to setup a relay and if it won't dmaage my HDD, that's all
You have yet to explain why you feel the need to disconnect power to the HDD.
Ransomware? But you are saying you wish to automate the process of connecting the backup drive. So if it is automated, then the moment it turns on, the ransomware will start working on it! Ergo, the XY problem!
To defeat ransomware, you store your backups on a Linux system which looks at the files on the network share and backs them up to a private home directory.
When you get that, there is no way to restore your backup files as there is no operating system that is functional. All the existing software on your HDD has been copied and encrypted and the person who did that is the only one to know the method and the keys. You basically need to get e new PC and restore your files to it.
I have backup/restore software on CD that will boot from the CD and restore the ENTIRE system from the backup, including the OS. My entire system is backed up one night to a USB HDD and in the morning I disconnect the HDD.