Happy accident - INCLUDES AN ALTERNATIVE TO SAFEPOINT

Appreciate that my formatting has been messed about by moving to the new forum system.

Here’s my attempt to sort out the formatting mess. I’ve tried to format

command line

And script file

line1
line2
line3
etc

With acknowledgements to Arty2, we’ll create the Python email script. Log in via SSH using PuTTY then:

nano /shares/system/Tasks/mail.py

Paste (right click) the following into the editor

#!/usr/bin/env python

#-*- coding: utf-8 -*-
from email.header import Header
from email.mime.text import MIMEText
from getpass import getpass
from smtplib import SMTP_SSL
import sys  

# edit the areas between the quotes in the line line below with your own settings

login, password, server, recipients = "the e.mail.account.you're.sending.from@gmail.com", "password", "smtp.gmail.com", "recipient@domain.com"  

# send email

subject = sys.argv[1]
body = sys.argv[2]
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.set_debuglevel(1)
try:s.login(login, password)
s.sendmail(msg['From'], recipients, msg.as_string())
except Exception, error:
print "Unable to send e-mail: '%s'." % str(error)
finally:
s.quit()

Come out of the editor. Now we’ll create the backup script

nano /shares/system/Tasks/backup.sh

# 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

crontab -e

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:

nano /shares/system/Tasks/restore.sh

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

nano /shares/system/Tasks/startrestore.sh

nohup /shares/system/Tasks/restore.sh > /dev/null 2>&1 &

exit and make this script executable

chmod +x /shares/system/Tasks/startrestore.sh

That’s it!!!

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:

./shares/system/Tasks/startrestore.sh