Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Scheduling Backups to NAS and waking from suspend

  1. #1
    Join Date
    Dec 2013
    Beans
    22

    Scheduling Backups to NAS and waking from suspend

    Hi there,
    I have been using Ubuntu 13.10 and have just about got it as I want. The only outstanding issue which is causing me a lot of headache is scheduled back ups.

    What I want to do is this: Every 4 weeks at 12:00, wake the computer from suspend, backup the home folder to the NAS drive (and delete the previous backup), suspend again.

    I have mounted the NAS as a bookmark using the instructions here http://www.youtube.com/watch?v=CGd0M3gNUCo
    Now every time I restart the PC, the NAS is a bookmark and I can click it and it loads the files no problem.

    I have tried a number of applications and can't seem to get a solution to what seems to be a simple problem!
    I am thinking that a command line solution using cron would maybe be the best bet

    Can anyone help me out here please?
    Thanks
    Last edited by steveearle86; January 17th, 2014 at 11:02 PM.

  2. #2
    Join Date
    Dec 2013
    Beans
    22

    Re: Scheduling Backups to NAS and waking from suspend

    I have been doing a bit of playing and am getting there. I have this:

    First, map the NAS drive as a local folder called NAS (as opposed to a bookmark which I was doing previously):
    sudo mount -t cifs -o username=steve //192.168.2.8/Volume_1 /NAS
    Backup home folder and sleep
    sudo rsync -av /home/steve/ /NAS && sudo pm-suspend
    The problem is that each time I restart, the drive needs mounting again, secondly, the command gives Permission Denied (13) for each file it tries to copy. When I change the rsync command to copy to a different folder (IE one on the local hard drive) it works perfectly.

    Any ideas?

  3. #3
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    8,582
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Scheduling Backups to NAS and waking from suspend

    Put the mount in your /etc/fstab. The NAS probably does not accept root copy attempts as a security precaution. You should be able to use rsync with your user privileges to copy your home account to the NAS. Otherwise, you don't have your NAS set up correctly.
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

  4. #4
    Join Date
    Dec 2013
    Beans
    22

    Re: Scheduling Backups to NAS and waking from suspend

    I have now completed this. Solution as follows:

    1. Auto mount the NAS as a local folder:
    -Edit fstab with gedit. Add the following as a line at the bottom of the file
    //<nas ip address>/<folder to mount> /NAS cifs credentials=/home/<nas username>/.smbcredentials,uid=<nas username>,gid=<nas username> 0 0
    2. Create shell script to run rsync and when complete, suspend the PC
    -in emacs, create new file
    -insert following:

    #!/bin/sh

    #Backup
    sudo rsync -av /home/<user> /NAS/Bedroom && sudo pm-suspend
    -save as home/<user>/backup.sh
    -make the script executable:
    chmod +x /home/<user>/backup.sh
    3.Use Cron to run the script at a specified interval
    -edit the root crontab:
    sudo crontab -e
    -add the following to crontab file to run backup .sh at 12 noon on the 1st of the month
    00 12 1 * * /home/<user>/backup.sh
    4.create script to suspend PC and wake at 11:55 on the 1st of the month
    -in Emacs, create shell script and save as suspendandwake.sh
    #!/bin/bash

    #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) ))


    #suspend the system and wake in this many seconds
    sudo rtcwake -m mem -s $DIFFERENCE
    -create a desktop launcher to run suspendandwake.sh and use instead of suspend option in menu bar

  5. #5
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    8,582
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Scheduling Backups to NAS and waking from suspend

    That is exactly how I would do it. One thing I would add, if there is an error in the rsync, send a text message to your phone.
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

  6. #6
    Join Date
    Dec 2013
    Beans
    22

    Re: Scheduling Backups to NAS and waking from suspend

    Thanks,
    I am only struggling with a few final tweaks:

    http://ubuntuforums.org/showthread.php?t=2198622
    <-- running suspendandwake.sh from launcher

    and when putting the computer to sleep with the suspendandwake.sh script, when the computer wakes up, it doesn't go to the same login/lock screen that you see if you had suspended from the system menu bar, it just wakes straight back into your desktop which is not ideal.

  7. #7
    Join Date
    Dec 2013
    Beans
    22

    Re: Scheduling Backups to NAS and waking from suspend

    Launcher Suspend issue now sorted. Just need to find a way to lock the screen on wake.....

  8. #8
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    8,582
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Scheduling Backups to NAS and waking from suspend

    Depending on what desktop environment you are running, there is a switch to lock the screen but it is found in screensaver settings. Check both activate screensaver when idle and lock screen with screensaver. This works for the most part, but there are some cases when the computer wakes without the screensaver and lock. You could add a logout command after a successful rsync and that would require a login on the next wake cycle.
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

  9. #9
    Join Date
    Dec 2013
    Beans
    22

    Re: Scheduling Backups to NAS and waking from suspend

    I think I have found the command with xscreensaver. However, I am struggling to get ANY command to run from a script from wake.

    As a test, I have created the following script:

    Code:
    #!/bin/bash 
    
    
    echo "hello" >> /home/steve/test.txt
    
    
    case "$1" in
        hibernate|suspend)
        #do nothing
    
    
            ;;
        thaw|resume)
            echo "THIS IS a test" >> /home/steve/test.txt
            ;;
    esac
    I have made this script executable by using chmod and place it in etc/pm/sleep.d and can run it from the terminal and outputs "hello" to the text file as expected. However, When restarting from suspend, there is no output to the file which suggests the file is not being run. I am using SuspendAndWake.sh above to suspend the PC.

    Any idas why the script is not executing?

  10. #10
    Join Date
    Feb 2007
    Location
    West Hills CA
    Beans
    8,582
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Scheduling Backups to NAS and waking from suspend

    Try sending the file to /tmp. It's possible that sleep and resume are acting on other than root privilege as a security improvement. And you should use test1.txt, test2.txt, and test3.txt so you can see which file gets written to and when. Put an extra echo command in the suspend case so you can see that call as well.
    -------------------------------------
    Oooh Shiny: PopularPages

    Unumquodque potest reparantur. Patientia sit virtus.

Page 1 of 2 12 LastLast

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
  •