Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Scheduling Backups to NAS and waking from suspend

  1. #11
    Join Date
    Sep 2013
    Beans
    24

    Re: Scheduling Backups to NAS and waking from suspend

    Deleted
    Last edited by Jason_Gibson; January 15th, 2014 at 04:47 AM.

  2. #12
    Join Date
    Dec 2013
    Beans
    28

    Re: Scheduling Backups to NAS and waking from suspend

    I have managed to narrow it down to an issue with rtcwake. I have the following amended file in etc/pm/sleep.d

    Code:
    #!/bin/bash 
    
    echo "run" >> /home/steve/test.txt
    
    
    case "$1" in
        hibernate|suspend)
    	echo "suspend" >> /home/steve/test.txt
    
    
    
    
            ;;
        thaw|resume)
            echo "wake" >> /home/steve/test.txt
            ;;
    esac
    If I run
    Code:
    sudo pm-suspend
    at the terminal, the output to the file "test.txt" reads

    run
    suspend
    run
    wake

    as expected.

    If I suspend the system with rtc wake:
    Code:
     rtcwake -m mem -s 20
    , the text is not written to the file.

    Any ideas on how I amend the rtcwake command in SuspendAndWake.sh above to put the system in the same sort of sleep as pm-suspend?

  3. #13
    Join Date
    Dec 2013
    Beans
    28

    Re: Scheduling Backups to NAS and waking from suspend

    Sorted,
    Forget all the above. I fixed by modifying SuspendAndWake.sh by putting

    Code:
    xscreensaver-command-lock
    before the final command.

    Thanks for the help

  4. #14
    Join Date
    Dec 2013
    Beans
    28

    Re: Scheduling Backups to NAS and waking from suspend

    A couple of further tweaks having notices some bugs:

    When restarting the system, chown settings are lost. Therefore I created a script called Chowner.sh:

    Code:
    sudo chown steve /dev/rtc
    sudo chown steve /sys/power/state
    I call this script from /etc/rc.local:

    Code:
    /home/steve/Chowner.sh
    Also xscreensaver was not running after a restart. It needs adding as a new startup programs entry with the following command

    Code:
    xscreensaver -no-splash
    Furthermore, there was a bug in backup.sh. I had put sudo at the beginning so it would ask for password. Furthermore, it does a suspend when complete, whereas I want it to do an rtcwake so it can wake again on the 1st of next month. backup.sh changed to:

    Code:
    rsync -av /home/steve /NAS/bedroom
    /home/steve/SuspendWake.sh
    Last edited by steveearle86; January 19th, 2014 at 08:24 PM.

  5. #15
    Join Date
    Dec 2013
    Beans
    28

    Re: Scheduling Backups to NAS and waking from suspend

    A few further amendments as the above was not sleeping the PC through the SuspendWake call when run through cron, however it was fine through the command line. I added the PATH line to the SuspendWake.sh and instead of calling backup.sh from the root crontab, made it run from the user's crontab.

    Updated SuspendWake.sh

    Code:
    #!/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/steve/SuspendWake.sh
    ############################################################
    ##puts the system to sleep and wakes at the specified time##
    ##    (just before the cron job to run backup runs)       ##
    ############################################################
    
    
    #current system time and waketime
    old=`date '+%H:%M'`
    new=11:55
    
    
    THISYEAR=`date +'%Y' -d 'now'`
    NEXTMONTH=`date +'%m' -d 'next month'`
    
    
    #if next month is January, increment the year by 1
    if [ $NEXTMONTH == 01 ]
    then
        THISYEAR=`date +'%Y' -d '1 year'`
    fi
    
    
    #current system date and wake date(1st of next month)
    olddate=`date +%Y-%m-%d`
    newdate=$THISYEAR"-"$NEXTMONTH"-01"
    
    
    IFS=: read old_hour old_min <<< "$old"
    IFS=: read hour min <<< "$new"
    
    
    # convert the date in seconds from Unix EPOCH time
    sec_old=$(date -d "$olddate $old_hour:$old_min:00" +%s)
    sec_new=$(date -d "$newdate $hour:$min:00" +%s)
    
    
    DIFFERENCE=$(( (sec_new - sec_old) )) 
    
    
    #lock the screen
    xscreensaver-command -lock
    
    
    #suspend the system and wake in this many seconds
    rtcwake -m mem  -s $DIFFERENCE

  6. #16
    Join Date
    Dec 2013
    Beans
    28

    Re: Scheduling Backups to NAS and waking from suspend

    Ok, does anyone have any ideas how I would execute some code if rsync fails for whatever reason?

  7. #17
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    10,049
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Scheduling Backups to NAS and waking from suspend

    Put exit 0 at the bottom of your backup.sh script. Put exit 1 at the line of your rsync with an appropriate test for "did it work?".

    Code:
    man test
    What errors are you seeing?

    You can add switches to rsync such as --stats and --log-file then perform a test on the log file for size of the backup or some other meanful parameter. If the test fails then exit 1 and use logger to make a system log entry that your rsync failed.

    There is probably a more elegant way to do this, but I'm tired and it is late.
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •