Centos – Keeping USB backup drive from sleeping while mounted

centoshard driveusb

Once every few days, seemingly at random, our backup to an external USB hard disk fails on our hp DL380 G5 server running CentOS 6.4 64-bit. If I cd /mnt/backup and run ls it complains ls: reading directory .: Input/output error, but mount -l reports /dev/sda1 on /mnt/backup type ext4 (rw). When I get someone on-site to check it out, they invariably report that the light on the external drive is slowly blinking, which is apparently normal for a sleep state. But I don't ask it to go into a sleep state until after rsnapshot runs, but rsnapshot causes my script to fail before that even has a chance to happen. Is it trying to save power? How can I get it to not do this?

rsnapshot complains:

/usr/bin/rsnapshot daily: ERROR: /mnt/backup/.snapshots does not exist.

Of course, if the person on-site unplugs and replugs the drive, I can remount it, and .snapshots certainly does exist and rsnapshot will run without errors. For a while until the next random occurrance, that is. BTW, this is a pretty new WD Passport drive.

So how do I tell it to stay awake?

Best Answer

If this hw poweroff were a normal function of the linux kernel, it handled it correctly. No, I think it is a wonderful surprise from the HP hardware.

I suggest a trivial workaround. Put into crontab:

* * * * * dd if=/dev/sda of=/dev/null bs=512 count=1

This will read in the partition table of the pendrive in every minute. It won't drop the life of the pendrive, because it made only read operations from it, but will prevents its sleep mode to turn on.

In my systems I never handled a such problem. If a pendrive was mounted, it was mounted, and if I forgot it and tried to use its partition after 2 weeks, it was able to be turned on, without a single kernel warning.