External USB Drive for Backup

Re: External USB Drive for Backup

Postby Jocko » Sat Apr 10, 2021 3:51 pm

Hi

indeed the information is missing in the help page. You can not use a cron job if you are not logged as admin (which it is not the case) or you never enable cron daemon. A technical share 'cronjob' is required to use this feature which is created as soon as you enable cron daemon.

So enable cron and then the feature should be available.
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: External USB Drive for Backup

Postby hvymetal86 » Sun Apr 11, 2021 8:11 pm

Thank you! I got Cron enabled and the button worked. I also scheduled a backup with cron for the Documents share. Used putty to cat out the whole .php file cron created for the job:
Code: Select all
root@HvyMtlNAS:/share/1100/cronjobs # cat Rsync_USB-Volume_1.from.Documents_puXb4Z.php
<?php
require_once("/etc/api/nasapi.inc");
$pid=getmypid();

//start php script
$start=date("Y-m-d_H:i:s");
echo "crond: USER root pid $pid Rsync script started at : $start\n";

//get on which volume the remote share is mounted
if(file_exists('/direct-usb'))
        $addons=str_replace(SHARE_MOUNTPOINT.'/','',readlink('/direct-usb'));
else
        $addons='1000';

//Check if the USB share is still mounted"
exec("sudo mount |grep ' on /share/$addons/Volume_1 '",$mounted);
$nb=count($mounted);
if ($nb < 1){
        // USB share not mounted in /share/1000
        echo "crond: USER root pid $pid USB share [Volume_1] not available !\n";
        nasapi("mrvlNotify 7 $start ".urlencode("USB share [Volume_1] not available !")." ".urlencode('/share/1100/Documents/')." ".urlencode('/share/1100/Volume_1/Documents'));
        $ret= 100;
}
else{
        preg_match('#^/dev/(s[ed][a-z])[0-9].*$#',$mounted[0],$dev);

        if(!isset($dev[1])|| $dev[1] ===""){
                echo "crond: USER root pid $pid Failed to check if the USB device is available !\n";
                nasapi("mrvlNotify 7 $start ".urlencode("Failed to check if USB device is available !")." ".urlencode('/share/1100/Documents/')." ".urlencode('/share/1100/Volume_1/Documents'));
                $ret=101;
        }
        elseif(preg_match('/(?:\(|,)ro,/',$dev[0])){
                echo "crond: USER root pid $pid No write access on USB drive !\n";
                nasapi("mrvlNotify 7 $start ".urlencode("No write access on USB device !")." ".urlencode('/share/1100/Documents/')." ".urlencode('/share/1100/Volume_1/Documents'));
                $ret=200;
        }
        else{
                // Check if the USB drive is still plugged".
                $block=glob('/sys/block/s*');
                foreach($block as $blk){
                        if($dev[1] == basename($blk)){
                                // USB drive is available
                                echo "crond: USER root pid $pid USB share is available\n";
                                $cmd = "umask 0 && /usr/sbin/rsync --stats --force --ignore-errors --modify-window=2 -tDvplogr --delete -b --backup-dir='../Documents_'`date +%Y-%m-%d_%H-%M-%S` '/share/1100/Documents/' '/share/1100/Volume_1/Documents'> '/share/1100/cronjobs/Documents_";
                                $date = date("Y-m-d_H-i-s");
                                $cmd .= $date.".log' 2>&1";
                                echo "crond: USER root pid $pid rsync command:\n";
                                echo "$cmd\n";
                                exec($cmd,$out,$ret);
                                if ($ret != 0){
                                        echo "crond: USER root pid $pid Rsync command returned some errors: see the log file (/share/1100/cronjobs/Documents_$date.log)!\n";
                                        echo "$ret\n";
                                }
                                else{
                                        echo "crond: USER root pid $pid Rsync command successful\n";
                                }
                                nasapi("mrvlNotify 6 $start ".urlencode("/share/1100/cronjobs/Documents_$date.log")." ".urlencode('/share/1100/Documents/')." ".urlencode('/share/1100/Volume_1/Documents'));
                                break;
                        }
                }
                if(!isset($ret)){
                        // USB drive not available
                        echo "crond: USER root pid $pid USB drive not available !\n";
                        nasapi("mrvlNotify 7 $start ".urlencode("USB device is not available !")." ".urlencode('/share/1100/Documents/')." ".urlencode('/share/1100/Volume_1/Documents'));
                        $ret=102;
                }
        }
}
echo "crond: USER root pid $pid Rsync script ended at : ".date("Y-m-d_H:i:s")."\n";
echo "$ret\n";


I also think running the backup once per day would be adequate and there aren't many changes on the NAS each day so I'm hoping it won't have an issue finishing the backup once a day.
hvymetal86
Donator VIP
Donator VIP
 
Posts: 121
Joined: Mon May 11, 2015 3:42 pm

Re: External USB Drive for Backup

Postby Jocko » Mon Apr 12, 2021 8:05 am

Hi

Attached the patched file.

if you examine it you will notice:
- it allows to backup all files from /share/1100
- it requires to exclude files from the USB disk as it is mounted on /share/1100/Volume_1 (so added an exclude option in rsync command)
- destination is now 'NAS_Back' as now it is no longer a single share which is synchronized.
- in NAS_Back, rsync will create a main subfolder 'Shares_xxxx' with a time stamp at each performing

So you have to replace the script in /share/1100/cronjobs or rename the new and in this last case you have to change the command line in cron
You do not have the required permissions to view the files attached to this post.
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Previous

Return to Lacie 5big Network vs2

Who is online

Users browsing this forum: No registered users and 13 guests