Announcement

Collapse
No announcement yet.

cron or other daily backups ... for a switched off notebook

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] cron or other daily backups ... for a switched off notebook

    I have a neat little backup script that gives me an exact snapshot of specified directories without reusing space for files that haven't changed (based on Easy Automated Snapshot-Style Backups with Rsync).

    But I haven't set it up as a cron job - I have to remember to run it manually - because I haven't worked out what happens if my computer is off at the scheduled time.

    I use a notebook. I suspend it overnight (and I hibernate it while travelling to and from work). So at any time when I'm not using it, it's likely to be off. How do you handle scheduling backup jobs to run in idle time when there isn't any idle time? Or in some other way avoid the backup job suddenly impacting your performance?

    Maybe I should just do an hourly run with nice and ionice. Or maybe there's a solution involving prompting: "run today's backup now" ... "you have not backed up for 6 days!" etc.
    I'd rather be locked out than locked in.

    #2
    You could place your backup job script in /etc/cron.daily/

    cron.daily jobs are run (and managed) by anacron which can handle running jobs to schedule even if the machine is turned off periodically.

    anacron jobs will run 'niced' so they shouldn't affect performance too much.

    More information ('man anacron', 'man anacrontab' and /etc/anacrontab)

    Comment


      #3
      http://askubuntu.com/questions/90816...-execution-tim
      Have you tried ?

      - How to Ask a Question on the Internet and Get It Answered
      - How To Ask Questions The Smart Way

      Comment


        #4
        I'll elaborate a bit in case you are wondering how anacron works:

        1. anacron will run daily at a time set in /etc/cron.d/anacron (if the machine is on at that time obviously)
        2. anacron will also run when you boot the machine or resume from suspend.

        3. Once anacron runs it'll check the timestamps of jobs defined in /etc/anacrontab, and if a job timestamp is older than the defined run interval in anacrontab, it'll run the job after a delay in minutes (also defined in anacrontab)...for example, if the timestamp for cron-daily is a day or more older it'll run the scripts in /etc/cron.daily. After the job is completed, it'll update the timestamp.

        So if you place a script in /etc/cron.daily...it will run daily at the time set in /etc/cron.d/anacron...or if the machine is turned off at that time it will run once you boot or resume the machine again (after a short configurable delay).

        Comment


          #5
          I'm looking at man anacron and man anacrontab and it looks ideal - thanks!
          I'd rather be locked out than locked in.

          Comment


            #6
            Update: my backup job ran under anacron. So all is good. Except ...

            I put my script into /etc/cron.daily/ which is the place anacron finds its daily jobs. There are a bunch of other scripts here, and anacron runs them in lexical order (obviously better than running them all at once). The problem is that /etc/cron.daily/apt has a built-in random delay of up to 30 minutes. So this delays nearly all the other jobs and I assumed at first my script, or the whole anacron scheme, was failing. And it may be that it can - if I switch on, work for 20 minutes and then switch off to go to work, I have no great confidence that it will still run smoothly.

            I think that's bad design for a cron job ... the random delay, which is thought to be to avoid thousands of machines from one time zone hitting the repository servers at the same time, should instead trigger another job to run later (at a random time later) and quit, allowing the other cron jobs to complete. But there seems to have been lots of discussion on this over the years and no changes.

            I'm not particularly keen to patch the apt job - it would get clobbered by upgrades, I imagine - so I'm thinking of calling my backup job aaabackup - or else calling it directly from /etc/anacrontab and allowing the hit of having it run in parallel with other jobs.
            I'd rather be locked out than locked in.

            Comment


              #7
              Originally posted by SecretCode View Post
              I'm not particularly keen to patch the apt job - it would get clobbered by upgrades, I imagine - so I'm thinking of calling my backup job aaabackup - or else calling it directly from /etc/anacrontab and allowing the hit of having it run in parallel with other jobs.
              Either should work, but if you also wish to disable or shorten the random time for the apt job, you can set the "APT::Periodic::RandomSleep" in /etc/apt/apt.conf.d/10periodic (or you can create your own file like /etc/apt/apt.conf.d/11my-periodic):
              APT::Periodic::RandomSleep "0"; (disables random sleep)
              APT::Periodic::RandomSleep "300"; (shorten interval to 5 minutes)

              (It might also be a good idea to change the time of the daily anacron run [/etc/cron.d/anacron] to avoid the "busy time" on the repos)
              Last edited by kubicle; Mar 05, 2012, 09:26 AM.

              Comment


                #8
                Thanks. I've set the RandomSleep ... and will test it in the morning!
                I'd rather be locked out than locked in.

                Comment

                Working...
                X