OK here goes, but I’ll add a couple of caveats -
Use at your own risk, I do not know whether this invalidates your warranty
There may be more elegant ways of doing the actual scripts, I’m just doing what worked for me.
Others may recognise some of their work in here, thank you for your help in getting me this far!
I also assume that anyone doing this has basic knowledge of WinSCP and PuTTY and has SSH access. I’m using the latest version of firmware. This doesn’t give an incremental backup, just an ongoing mirror of your shares.
Using WinSCP (easiest) or PuTTY create a folder called “Backup” on your USB drive, inside that folder create a separate folder for each of your shares. It may also be worth renaming the share name of your USB drive to something simple such as “USBbackup” which is the name I’ll use here.
To prevent your scripts being overwritten by future firmware updates, create a share called ‘system’ (for example) and place a folder in there called, say 'Tasks". I shall use these and the above names in what’s to follow.
With acknowledgements to Arty2, we’ll create the Python email script. Go into PuTTY then:
nano /shares /system/Tasks/mail.py
Paste (right click) the following into the editor
-*- coding: utf-8 -*-from email.header import Header
from email.mime.text import MIMEText
from getpass import getpass
from smtplib import SMTP_SSL
#edit the areas between the quotes in the line line below with your own settings
login, password, server, recipients = “the e.mail.account.you’email@example.com”, “password”, “smtp.gmail.com”, "firstname.lastname@example.org"
subject = sys.argv
body = sys.argv
msg = MIMEText(body, ‘plain’, ‘utf-8’)
msg[‘Subject’] = Header(subject, ‘utf-8’)
msg[‘From’] = login
msg[‘To’] = recipients
s = SMTP_SSL(server, 465, timeout=10)
s.sendmail(msg[‘From’], recipients, msg.as_string())
except Exception, error:
print “Unable to send e-mail: ‘%s’.” % str(error)
Come out of the editor. Now we’ll create the backup script
add your share names where share1 etc appear below
rsync -a /shares/share1/ /var/media/USBbackup/Backup/share1/
rsync -a /shares/share2/ /var/media/USBbackup/Backup/share2/
Continue adding as many shares as you like using the above syntax
Finally, the email to confirm the backup completed
python /shares/system/Tasks/mail.py “Message from WD MyCloud” “System backup has been completed successfully”
Having come out of the editor, make the script executable:
chmod +x /shares/system/Tasks/backup.sh
Now add a task with crontab, the following will run the backup at 0100 each day
add the line
00 01 * * * /shares/system/Tasks/backup.sh
Your backup will run at the required time and will send you an email when the task is completed.
That’s it for the backup. By the sheer speed of what happened, my USB drive stayed connected throughout the ‘wipe’ and reboot without problems.
For restoring, have a script ready, once again using nano, as my shares are quite large I wanted to keep an eye on progress so asked it to send me an email after each share had been restored:
rsync -a /var/media/USBbackup/share1/ /shares/share1/
python /shares/system/Tasks/mail.py “Message from WD MyCloud” “Share1 restore has been completed successfully”
rsync -a /var/media/USBbackup/share2/ /shares/share2/
python /shares/system/Tasks/mail.py “Message from WD MyCloud” “Share2 restore has been completed successfully”
add further shares as you wish, exit and save
make this script executable
chmod +x /shares/system/Tasks/restore.sh
now a final script, this will enable you to send an instruction to the MC to execute the restore script unattended
nohup /shares/system/Tasks/restore.sh > /dev/null 2>&1 &
exit and make this script executable
chmod +x /shares/system/Tasks/startrestore.sh
To recover after a wipe of your MC, once you’ve manually set up your shares again, configured the MC and given yourself SSH access (not forgetting changing the root password), use WinSCP to manually copy the backup of your ‘system’ share to the MC (should only take a min), then open PuTTY.
Give it the command:
The restore will start running, PuTTY will return almost immediately to the command prompt, the restore will run in the background without any further intervention, and you’ll get emails to tell you how it’s going.
Of course if you just want to restore the odd file or folder that you’ve accidentally lost you can use WinSCP to copy the files/folders across from the USB drive.
Hope this is of help. There may be typos or unintended line-breaks in the above for which I apologise.