Menu
blog.headdesk.me
blog.headdesk.me

Backup to USB drive and power it off when not in use

Posted on 2015/07/022015/07/02

On Linux, it is possible to power off a USB device using command line. It’s perfect for my USB backup drive. I can power it off after backup every night, and power it on before the job starts. This saves power, reduce heat, and more importantly, prevent accidental or unexpected changes as the device is completely offline.

The command to turn off/on a USB device requires the USB address. To find it, I look for “Toshiba” in dmesg and 2-1 is the address.

# dmesg | grep -i toshiba
[    2.401262] usb 2-1: Manufacturer: TOSHIBA

Now I have the address, I can power off the device with the following command

$ echo 2-1 > /sys/bus/usb/drivers/usb/unbind

To bring it back on

$ echo 2-1 > /sys/bus/usb/drivers/usb/bind

And when it’s powered on, the kernel reported the device as if it’s just plugged in:

[605419.258985] usb-storage 2-1:1.0: USB Mass Storage device detected
[605419.259151] scsi host11: usb-storage 2-1:1.0
[605420.263369] scsi 11:0:0:0: Direct-Access     TOSHIBA  External USB 3.0 5438 PQ: 0 ANSI: 6
[605420.264876] sd 11:0:0:0: Attached scsi generic sg4 type 0
[605420.267811] sd 11:0:0:0: [sdd] 3907029164 512-byte logical blocks: (2.00 TB/1.81 TiB)
[605420.268293] sd 11:0:0:0: [sdd] Write Protect is off
[605420.268302] sd 11:0:0:0: [sdd] Mode Sense: 23 00 00 00
[605420.268783] sd 11:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[605425.980615]  sdd: sdd1
[605425.983234] sd 11:0:0:0: [sdd] Attached SCSI disk

Now if you run a Linux desktop like I do and you don’t want the system to automatically mount the drive under a generated path, simply add a “noauto” option to fstab and mount it in the backup script.

facebookShare on Facebook
TwitterTweet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Full text search

Recent Posts

  • Dumping AWS Organization tree
  • Free is the most expensive
  • Terraform conditional resource and blocks
  • Upgrade Ubuntu 16.04 to latest release
  • Inspect and control network traffic on AWS
  • aws (8)
  • coffee (1)
  • headfi (1)
  • linux (7)
  • others (55)
  • security (2)
  • tech (36)
  • wordpress (2)

apache aws awscli azure backup cloud coffee coreos distributed filesystem docker ec2 EL8 elasticcache etckeeper featured heartbleed kernel linux mail meltdown mysql php pine python rdp rds Redhat Red Hat RHEL RHEL7 rpm Ryzen snapshot spectre SSL systemd tech terraform ubuntu ubuntu upgrade vector vpn wordpress xtreemfs yum

©2022 blog.headdesk.me | Powered by SuperbThemes & WordPress