[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Automatic Backup Script Help



On Wed, May 23, 2012 at 1:04 PM, Craig A. Adams <craigaa@iafrica.com> wrote:
> Thank you for the feedback Jon. :-)
>
>
> On 23/05/2012 09:12 AM, Jon Dowland wrote:
>>
>>   { sleep 60; /data/backups/scripts/backup-disk-1.sh }&
>>
>> But I don't see why you even need the sleep.
>
>
> I agree. I suspect using sleep will merely suspend udev operations as well.
>
>
>> should be backticks here so that date is evaluated e.g.
>>
>> start_date_time=`date +%Y-%m-%d-%H:%M:%S`
>
>
> Thank you. Not being an experiences bash scripter, I always seem to get lost
> on the proper delimeters.
>
>
>>
>>> if -a /data/backups/${backup_description}-in-progress; then
>>>        echo "FAIL ${backup_description} backup already in progress."
>>>        exit 1
>>> else touch /data/backups/${backup_description}-in-progress
>>> fi
>>
>>
>> There is a risk of race conditions here, if two instances of your script
>> are fired off at similar times. E.g., whilst instance #1 has performed
>> the check, instance #2 creates the file…  Better would be a proper locking
>> solution. (sorry I'm not offering one in this reply)
>
>
> That is what I am trying to achieve by the progress file. I have noticed
> that sometimes with usb, the device is "discovered" multiple times. So I
> want to prevent multiple instances of the script. I will obviously need to
> find a better locking mechanism.
>

flock from the util-linux package:

FLOCK(1)

NAME
       flock - manage locks from shell scripts

SYNOPSIS
       flock [-sxon] [-w timeout] lockfile [-c] command...

       flock [-sxon] [-w timeout] lockdir [-c] command...

       flock [-sxun] [-w timeout] fd

>
>>
>>> if ! mountpoint -q ${backup_target}/; then
>>
>>
>> risk of races here
>>
>>>        if ! mount ${backup_target}; then
>>
>>
>> and here
>>
>
> I am lost here. I thought that this would be a simple mountpoint check. Is
> there a better way to mount and check if the drive is mounted?
>


-- 
regards,
kushal


Reply to: