rsync-time-backup icon indicating copy to clipboard operation
rsync-time-backup copied to clipboard

How to work this script with launchd on OS X

Open debaron opened this issue 6 years ago • 2 comments

Having major issues trying to get this to work with launchd. The colon in ssh login fails it when quoting entire line e.g. ~/Library/Scripts/myscript.sh source user@host:destination

I can get around if it is possible to set following options in script itself rather than on command line - would be preferred option. Tried in a few locations no luck

Source - username - host - destination

Can anyone help?

debaron avatar Dec 05 '17 17:12 debaron

  • On my OSX machine, I use a personal crontab. not launchd - and not a root crontab entry.

  • Follow this for general setup as a tip for how crontab works. https://ole.michelsen.dk/blog/schedule-jobs-with-crontab-on-mac-osx.html

  • Ensure your ssh keys are setup on the remote host, and test it with ssh user@my-backup-server-with-ssh-keys uptime

  • In the example below, I have this repo checked out to /Users/rbuckland/projects/github.com/laurent22/rsync-time-backup

  • The crontab I found that works is;

    15:58 $ crontab -l
    0 */3 * * * if [[ $( ssh my-backup-server-with-ssh-keys uptime ) ]]; then /Users/rbuckland/projects/github.com/laurent22/rsync-time-backup/rsync_tmbackup.sh /Users/rbuckland rbuckland@my-backup-server-with-ssh-keys:/home/rbuckland/backups/rsync-time-backup /Users/rbuckland/.workstation/backup_exclusions.txt; fi
    
    • check the host is up. (sufficient for roaming on and off the network)
    • backup runs every 3 hours; if it can; ssh my-backup-server-with-ssh-keys uptime performs that check.
    • the crontab entry under my user (change / edit it with crontab -e)
  • my exclusions (as an example)

    15:59 $ cat ~/.workstation/backup_exclusions.txt
    Applications
    Downloads
    Library
    Public
    backups
    .DS_Store
    *.swp
    .Trash
    .atom
    .bash_sessions
    .cups
    .gem
    .log
    .matplotlib
    .npm
    .oracle_jre_usage
    .rsync_tmbackup
    .m2
    .ivy
    
  • and after 3 months i see

    rbuckland@my-backup-server-with-ssh-keys:~/backups/rsync-time-backup$ ls -al
    total 84
    drwxrwxr-x 21 rbuckland rbuckland 4096 Apr 18 15:00 .
    drwxrwxr-x  5 rbuckland rbuckland 4096 Jan 19 10:15 ..
    drwxr-xr-x 17 rbuckland rbuckland 4096 Jan 31 11:57 2018-01-31-120001
    drwxr-xr-x 20 rbuckland rbuckland 4096 Feb 26 11:54 2018-02-26-120047
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 19 14:14 2018-03-19-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 20 14:14 2018-03-20-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 21 17:56 2018-03-21-180001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 22 13:00 2018-03-22-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 24 19:38 2018-03-24-210002
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 25 16:58 2018-03-25-180003
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 26 14:59 2018-03-26-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 27 14:17 2018-03-27-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 28 14:57 2018-03-28-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 29 14:31 2018-03-29-150001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr  3 14:04 2018-04-03-150002
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr  4 11:47 2018-04-04-120003
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr  5 17:24 2018-04-05-180001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr  6 14:41 2018-04-06-150003
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 16 09:09 2018-04-16-120001
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 17 14:42 2018-04-17-150002
    drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 18 13:52 2018-04-18-150001
    -rw-rw-r--  1 rbuckland rbuckland    0 Jan 19 09:36 backup.marker
    lrwxrwxrwx  1 rbuckland rbuckland   17 Apr 18 15:00 latest -> 2018-04-18-150001
    

rbuckland avatar Apr 18 '18 06:04 rbuckland

Awesome thank you Ramon

Ryan Maunder

Senior Engineer

26 Oxford Street St. Philips Bristol England BS2 0QT | Tel: + 44 (0)117 370 5858 | Mob: + 44 (0)7852 186547

Registered in England No 5728793 | Registered Office: 24 North Street Bristol BS3 1HW | VAT Reg No 879 5619 54

http://www.iTech-net.co.uk http://www.itech-net.co.uk/

Internet communications are not secure and therefore iTech does not accept legal responsibility for the contents of this message. Any views or opinions presented are solely those of the author and do not necessarily represent those of iTech Networks Ltd.

On 18 Apr 2018, at 07:31, Ramon Buckland [email protected] wrote:

On my OSX machine, I use a personal crontab. not launchd - and not a root crontab entry.

Follow this for general setup as a tip for how crontab works. https://ole.michelsen.dk/blog/schedule-jobs-with-crontab-on-mac-osx.html https://ole.michelsen.dk/blog/schedule-jobs-with-crontab-on-mac-osx.html Ensure your ssh keys are setup on the remote host, and test it with ssh user@my-backup-server-with-ssh-keys uptime

In the example below, I have this repo checked out to /Users/rbuckland/projects/github.com/laurent22/rsync-time-backup

The crontab I found that works is;

15:58 $ crontab -l 0 */3 * * * if [[ $( ssh my-backup-server-with-ssh-keys uptime ) ]]; then /Users/rbuckland/projects/github.com/laurent22/rsync-time-backup/rsync_tmbackup.sh /Users/rbuckland rbuckland@my-backup-server-with-ssh-keys:/home/rbuckland/backups/rsync-time-backup /Users/rbuckland/.workstation/backup_exclusions.txt; fi check the host is up. (sufficient for roaming on and off the network) backup runs every 3 hours; if it can; ssh my-backup-server-with-ssh-keys uptime performs that check. the crontab entry under my user (change / edit it with crontab -e) my exclusions (as an example)

15:59 $ cat ~/.workstation/backup_exclusions.txt Applications Downloads Library Public backups .DS_Store *.swp .Trash .atom .bash_sessions .cups .gem .log .matplotlib .npm .oracle_jre_usage .rsync_tmbackup .m2 .ivy and after 3 months i see

rbuckland@my-backup-server-with-ssh-keys:~/backups/rsync-time-backup$ ls -al total 84 drwxrwxr-x 21 rbuckland rbuckland 4096 Apr 18 15:00 . drwxrwxr-x 5 rbuckland rbuckland 4096 Jan 19 10:15 .. drwxr-xr-x 17 rbuckland rbuckland 4096 Jan 31 11:57 2018-01-31-120001 drwxr-xr-x 20 rbuckland rbuckland 4096 Feb 26 11:54 2018-02-26-120047 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 19 14:14 2018-03-19-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 20 14:14 2018-03-20-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 21 17:56 2018-03-21-180001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 22 13:00 2018-03-22-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 24 19:38 2018-03-24-210002 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 25 16:58 2018-03-25-180003 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 26 14:59 2018-03-26-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 27 14:17 2018-03-27-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 28 14:57 2018-03-28-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Mar 29 14:31 2018-03-29-150001 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 3 14:04 2018-04-03-150002 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 4 11:47 2018-04-04-120003 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 5 17:24 2018-04-05-180001 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 6 14:41 2018-04-06-150003 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 16 09:09 2018-04-16-120001 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 17 14:42 2018-04-17-150002 drwxr-xr-x 22 rbuckland rbuckland 4096 Apr 18 13:52 2018-04-18-150001 -rw-rw-r-- 1 rbuckland rbuckland 0 Jan 19 09:36 backup.marker lrwxrwxrwx 1 rbuckland rbuckland 17 Apr 18 15:00 latest -> 2018-04-18-150001 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laurent22/rsync-time-backup/issues/101#issuecomment-382277526, or mute the thread https://github.com/notifications/unsubscribe-auth/AgsXVtXL33xuPnDzyFmNSIp9nsFd_iI7ks5tpt2_gaJpZM4Q2qr9.

debaron avatar Apr 18 '18 08:04 debaron