├── .gitignore ├── server ├── backup-thinkpad.sh └── README.md ├── LaunchAgent ├── README.md └── backup.workmac.plist ├── anacron ├── backup └── README.md ├── test_runner.clj ├── test └── eamonnsullivan │ └── backup_test.clj ├── README.md ├── src └── eamonnsullivan │ └── backup.clj └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .cider-repl-history 2 | .clj-kondo/ 3 | .cpcache/ 4 | -------------------------------------------------------------------------------- /server/backup-thinkpad.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | /media/backup/backup.clj root@thinkpad.local:/home thinkpad >>/var/log/backups/backup_thinkpad.log 2>&1 4 | -------------------------------------------------------------------------------- /LaunchAgent/README.md: -------------------------------------------------------------------------------- 1 | # Example launchd.plist 2 | 3 | This is an example of a configuration file that goes in `~/Library/LaunchAgents/` on the Mac. See the main page for `launchd.plist` for more about the format. 4 | -------------------------------------------------------------------------------- /anacron/backup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | /usr/bin/ssh einstein.local /media/backup/backup-thinkpad.sh 4 | EXITVALUE=$? 5 | if [ $EXITVALUE != 0 ]; then 6 | /usr/bin/logger -t backup "ALERT exited abnormally with [$EXITVALUE]" 7 | fi 8 | exit $EXITVALUE 9 | -------------------------------------------------------------------------------- /server/README.md: -------------------------------------------------------------------------------- 1 | # Sample Start script for the service 2 | 3 | This is an example of a very short bash script that sits on the service. It's only real purpose is to make the ssh command from the laptop simpler. The laptops just call a script like this, which in turn calls the main back up script. 4 | -------------------------------------------------------------------------------- /anacron/README.md: -------------------------------------------------------------------------------- 1 | # Example Anacron script 2 | 3 | This is an example of a script you would place in `/etc/cron.daily` to initiate the back up. The laptop will try running this script once a day, when it wakes up. 4 | 5 | For this to work, you will need password-less access to the back up PC over ssh. 6 | -------------------------------------------------------------------------------- /test_runner.clj: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bb 2 | 3 | (require '[clojure.test :as t] 4 | '[babashka.classpath :as cp]) 5 | 6 | (cp/add-classpath "src:test") 7 | 8 | (require 'eamonnsullivan.backup-test) 9 | 10 | (def test-results 11 | (t/run-tests 'eamonnsullivan.backup-test)) 12 | 13 | (def failures-and-errors 14 | (let [{:keys [:fail :error]} test-results] 15 | (+ fail error))) 16 | 17 | (System/exit failures-and-errors) 18 | -------------------------------------------------------------------------------- /LaunchAgent/backup.workmac.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | backup.workmac 7 | ProgramArguments 8 | 9 | /usr/bin/ssh 10 | einstein.local 11 | /media/backup/backup-workmac.sh 12 | 13 | KeepAlive 14 | 15 | SuccessfulExit 16 | 17 | 18 | ThrottleInterval 19 | 60 20 | StartCalendarInterval 21 | 22 | Minute 23 | 0 24 | Hour 25 | 11 26 | 27 | StandardOutPath 28 | /usr/local/var/log/backup-workmac.log 29 | StandardErrorPath 30 | /usr/local/var/log/backup-workmac.log 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/eamonnsullivan/backup_test.clj: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bb 2 | 3 | (ns eamonnsullivan.backup-test 4 | {:author "Eamonn Sullivan"} 5 | (:import (java.time LocalDateTime)) 6 | (:require [eamonnsullivan.backup :as sut] 7 | [babashka.fs :as fs] 8 | [clojure.java.io :as io] 9 | [clojure.test :as t :refer [deftest testing is]])) 10 | 11 | (def cwd (fs/real-path ".")) 12 | 13 | (defn temp-dir [] 14 | (-> (fs/create-temp-dir) 15 | (fs/delete-on-exit))) 16 | 17 | (deftest test-new-month? 18 | (with-redefs [sut/get-current-month (fn [] "2020-01")] 19 | (testing "compares the year and month" 20 | (is (= false 21 | (sut/new-month? "2020-01")))))) 22 | 23 | (deftest retry-test 24 | (testing "should retry the specified number of times" 25 | (is (= 4 ;; first, then three retries. 26 | (let [attempts-count (volatile! 0) 27 | _ (sut/retry #(vswap! attempts-count inc) :continue 3 100)] 28 | @attempts-count)))) 29 | (testing "should stop retrying when predicate returns true" 30 | (is (= 3 31 | (let [attempts-count (volatile! 0) 32 | _ (sut/retry #(vswap! attempts-count inc) (fn [_] (< 2 @attempts-count)) 5 100)] 33 | @attempts-count))))) 34 | 35 | (deftest test-link 36 | (let [tmp-dir (temp-dir) 37 | dir (str (fs/create-dir (fs/path tmp-dir "foo"))) 38 | _ (spit (fs/file tmp-dir "foo/" "dudette.txt") "some content") 39 | linkto (str tmp-dir "/bar") 40 | _ (sut/link dir linkto)] 41 | (is (.exists (fs/file tmp-dir "foo"))) 42 | (is (.exists (fs/file tmp-dir "bar"))) 43 | (is (.exists (fs/file tmp-dir "bar/" "dudette.txt"))) 44 | (is (= (slurp (fs/file tmp-dir "foo/" "dudette.txt")) 45 | (slurp (fs/file tmp-dir "bar/" "dudette.txt")))) 46 | (is (= 2 (fs/get-attribute (fs/file tmp-dir "bar/" "dudette.txt") 47 | "unix:nlink"))))) 48 | 49 | (deftest test-delete-backup 50 | (let [tmp-dir (temp-dir) 51 | _ (fs/create-dir (fs/path tmp-dir "foo")) 52 | _ (fs/create-dir (fs/path tmp-dir "bar")) 53 | _ (spit (fs/file tmp-dir "bar/" "something.txt") "with content") 54 | _ (spit (fs/file tmp-dir "foo/" "dude.txt") "some content")] 55 | (binding [sut/*base-path* tmp-dir] 56 | (sut/delete-backup "foo") 57 | (is (.exists (fs/file tmp-dir "bar"))) 58 | (is (not (.exists (fs/file tmp-dir "foo"))))))) 59 | 60 | (deftest test-get-backup-usage 61 | (let [tmp-dir (temp-dir) 62 | _ (fs/create-dir (fs/path tmp-dir "foo")) 63 | _ (spit (fs/file tmp-dir "foo/" "content.txt") "123\n")] 64 | (binding [sut/*base-path* tmp-dir] 65 | (is (= 4100 66 | (sut/get-backup-usage "foo")))))) 67 | 68 | (deftest test-check-month 69 | (let [tmp-dir (temp-dir) 70 | _ (fs/create-dir (fs/path tmp-dir "foo")) 71 | _ (spit (fs/file tmp-dir "foo/" "content.txt") "123") 72 | _ (spit (fs/file tmp-dir "checkMonth_foo.txt") "456")] 73 | (binding [sut/*base-path* tmp-dir] 74 | (with-redefs [sut/new-month? (fn [_] false)] 75 | (testing "does not delete current backup if the month hasn't changed" 76 | (sut/check-month "foo") 77 | (is (.exists (fs/file tmp-dir "foo"))))) 78 | (with-redefs [sut/new-month? (fn [_] true) 79 | sut/get-current-month (fn [] "789")] 80 | (testing "removes current backup and writes new checkMonth file when month changes" 81 | (sut/check-month "foo") 82 | (is (not (.exists (fs/file tmp-dir "foo/" "content.txt")))) 83 | (is (= "789" 84 | (slurp (fs/file tmp-dir "checkMonth_foo.txt"))))))))) 85 | 86 | (deftest test-make-hard-link 87 | (let [tmp-dir (temp-dir) 88 | _ (fs/create-dir (fs/path tmp-dir "foo")) 89 | _ (spit (fs/file tmp-dir "foo/" "content.txt") "123")] 90 | (binding [sut/*base-path* tmp-dir] 91 | (testing "makes a hard-link under /old of the current backup" 92 | (sut/make-hard-link "foo" "foo-123") 93 | (is (.exists (fs/file tmp-dir "old/foo-123/" "content.txt"))))))) 94 | 95 | (deftest test-oldest-dir 96 | ;; My slower Linux system seems to need the sleeps... 97 | (let [tmp-dir (temp-dir) 98 | _ (fs/create-dir (fs/path tmp-dir "one")) 99 | _ (Thread/sleep 10) 100 | _ (fs/create-dir (fs/path tmp-dir "two")) 101 | _ (Thread/sleep 10) 102 | _ (fs/create-dir (fs/path tmp-dir "three"))] 103 | (testing "should find oldest directory by last modified" 104 | (is (= (fs/path tmp-dir "one") 105 | (fs/path (sut/oldest-dir (str tmp-dir)))))))) 106 | 107 | (deftest test-delete-oldest-backup 108 | (let [tmp-dir (temp-dir) 109 | _ (fs/create-dir (fs/path tmp-dir "old")) 110 | _ (fs/create-dir (fs/path tmp-dir "old/" "one")) 111 | _ (Thread/sleep 10) 112 | _ (fs/create-dir (fs/path tmp-dir "old/" "two")) 113 | _ (Thread/sleep 10) 114 | _ (fs/create-dir (fs/path tmp-dir "old/" "three"))] 115 | (testing "should remove the old directory under /old" 116 | (binding [sut/*base-path* tmp-dir] 117 | (sut/delete-oldest-backup) 118 | (is (not (.exists (fs/file tmp-dir "old/" "one")))) 119 | (is (.exists (fs/file tmp-dir "old/" "two"))) 120 | (is (.exists (fs/file tmp-dir "old/" "three"))))))) 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # My backup scripts 2 | 3 | These are my current scripts for backing up three laptops around the house to a desktop PC. It is also a small experiment in using [babashka](https://github.com/babashka/babashka), a scripting flavour of the Clojure language. 4 | 5 | I had never used babaskha, so this is very unlikely to be a good example for anyone else. For much better information and examples, see babashka's [online book](https://book.babashka.org/#introduction). 6 | 7 | ## Main goals and outcomes 8 | 9 | The main reason I was revisiting my home backup scripts it that we've transitioned over the years from a household of two or three standard PCs, to one with three laptops. 10 | 11 | I used to mirror my family's home directories to an external drive. I used Time Machine on the Mac and [cron](http://manpages.ubuntu.com/manpages/focal/en/man3/cron.3tcl.html) and [rsync](http://manpages.ubuntu.com/manpages/focal/man1/rsync.1.html) on Linux. That mostly just worked. 12 | 13 | Laptops are a new challenge, though. You can't just go around with an external drive hanging off them. They're often sleeping, with the lid down, on a sofa somewhere and (unless it's the work laptop) used intermittently. 14 | 15 | My solution, at the moment, is to back up centrally (using the [server-side script](src/eamonnsullivan/backup.clj) that is the main focus of this repo), but have the laptops initiate the process by running small shell scripts over ssh. I'm using [anacron](http://manpages.ubuntu.com/manpages/focal/man8/anacron.8.html) on Ubuntu and launchctl/launchd on the Mac to configure the laptops to back themselves up once a day. 16 | 17 | ### Why do I still need backups? 18 | 19 | That's a question worth considering. Why not just use Dropbox, Google Drive or whatever Apple's pushing these days? I do actually already use these things, plus Github for all of my source code. 20 | 21 | But these aren't back up systems. If I accidentally delete an important file, for example, it's very shortly gone from these systems as well. 22 | 23 | Also, my wife (who doesn't use Dropbox or anything like it) keeps her entire digital life (word processing documents, presentation, spreadsheets, etc.) on a Thinkpad running Ubuntu. She counts on me to keep those safe. (Well, actually, she just assumes they are safe... I'm the IT Guy in the house and it's my job to worry about such things.) 24 | 25 | Mostly, though, I like having control over my own data and I want to understand how it is being stored and moved around. I will probably extend this system to the cloud in the future -- periodically sending monthly backups offsite -- but I will likely use S3 on my own AWS account for that, keeping it under my understanding and control. 26 | 27 | ## Prerequisites 28 | 29 | You'll need a PC that's either always on or reliably turned on when it's needed. It will need plenty of disk storage. A Raspberry Pi 4 with an attached USB disk is what I use at the moment. I installed the ARM port of Ubuntu server on it, and babashka now has ARM support as well. 30 | 31 | I use a 1TB SSD USB disk, mounted permanently at /media/backup. Here's [one random guide](https://www.techrepublic.com/article/how-to-properly-automount-a-drive-in-ubuntu-linux/) on how to mount an external disk automatically on boot. 32 | 33 | You will also need to set up password-less SSH access, both from the back up PC to the devices, and from the devices to the back up PC. This will allow the back up PC to run rsync to the devices, and also allow to the devices to kick off the process by running a small shell script via SSH. There are a lot of guides on the Internet for this, such as [this one](https://linuxize.com/post/how-to-setup-passwordless-ssh-login/). 34 | 35 | I don't use Windows at the moment and don't really mount network drives, either. That might be a good alternative to consider. 36 | 37 | ## Back up approach 38 | 39 | I used to just mirror everyone's home directory on another device. Just periodically run rsync and sync all of the files to the external hard drive. This works, but it has a couple of disadvantages. One important disadvantage is that if you delete a file on Tuesday and discover on Thursday that you really actually needed that file, it's probably now gone from the back up, as well. 40 | 41 | So, instead I took a cue from Apple's Time Machine and take advantage of hard links, a relatively underused facility in most Unix based file systems. Basically, it just gives the file another name, somewhere else. If you delete one of the names, the same file still lives under the other name. And hard links don't take up any extra space (or hardly any). 42 | 43 | I also mitigate against creeping bad sectors (which happen even on SSDs) by periodically starting over again with a fresh, full back up. 44 | 45 | The basic algorithm: 46 | 47 | 1. Run rsync to sync the files from one place to another. 48 | 1. Make a hard link of all of the files to another location on the file system, under a directory with the date in the name. 49 | 1. Check the remaining free space on the back up device and compare it with the last full back I just did. If free space is less than twice the size of the last backup, I start removing the oldest backups (the ones created in the last step) until I have that much remaining. 50 | 1. Once a month, I start a new full back up from scratch. This is to guard against bad sectors in the disk, which can make older files become unreadable, and you would never know until you tried to restore it. 51 | 52 | ## Example scripts 53 | 54 | * [LaunchAgent on the Mac laptop](LaunchAgent/) 55 | * [Anacron script for the Ubuntu laptops](anacron/) 56 | * [Starter script on the server](server/) 57 | * [Main back up script](src/eamonnsullivan/backup.clj) 58 | 59 | ## License 60 | 61 | Copyright © 2021 Eamonn Sullivan 62 | 63 | Distributed under the Eclipse Public License version 1.0. 64 | -------------------------------------------------------------------------------- /src/eamonnsullivan/backup.clj: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bb 2 | 3 | (ns eamonnsullivan.backup 4 | "A wrapper around rsync that manages multiple backups of multiple 5 | hosts. After each backup, it creates a hard link (effectively 6 | creating a snapshot of the current difference since the previous 7 | backup) and checks the free space available on the storage 8 | device. If free space is less than double the size of the most 9 | recent backup, we remove older backups. 10 | 11 | At the start of a new month, we begin a fresh backup. This is to 12 | avoid any potential issues with bad sectors. 13 | 14 | Usage: 15 | 16 | Examples: backup.clj root@thinkpad.local:/home thinkpad 17 | backup.clj sullie09@mc-s105910.local:~ workmac" 18 | {:author "Eamonn Sullivan"} 19 | (:import (java.time.format DateTimeFormatter) 20 | (java.time LocalDateTime)) 21 | (:require [clojure.java.io :as io] 22 | [clojure.java.shell :refer [sh]] 23 | [clojure.string :as string] 24 | [babashka.fs :as fs])) 25 | 26 | (def ^:dynamic *base-path* "/media/backup") 27 | (def ^:dynamic *rsync-command* ["rsync" "-avzpH" "--partial" "--delete" "--exclude-from=/etc/rsync-backup-excludes.txt"]) 28 | 29 | (def month-formatter (DateTimeFormatter/ofPattern "yyyy-MM")) 30 | (def date-time-formatter (DateTimeFormatter/ofPattern "yyyy-MM-dd_HH-mm-s")) 31 | 32 | (defn retry 33 | "Retry function f, n times and check whether it succeeded with the 34 | predicate success?" 35 | ([f success? num-retries] 36 | (retry f success? num-retries 30000)) 37 | ([f success? num-retries wait-time] 38 | (if (zero? num-retries) 39 | (f) 40 | (let [result (f)] 41 | (if (not (success? result)) 42 | (do 43 | (println (format "Function failed with error [%s], retrying" (:err result))) 44 | (Thread/sleep wait-time) 45 | (retry f success? (dec num-retries) wait-time)) 46 | result))))) 47 | 48 | (defn get-current-month 49 | "Get a string that includes the year and month." 50 | [] 51 | (.format (LocalDateTime/now) month-formatter)) 52 | 53 | (defn link 54 | "Create a hard link from path to target." 55 | [path target] 56 | (sh "cp" "-al" path target)) 57 | 58 | (defn write-check-month-file 59 | "Write out the current year and month into a backup-specific file that 60 | we can compare against. Used so that we can more easily tell when 61 | we've changed months since the last backup." 62 | [content backup] 63 | (spit (format "%s/checkMonth_%s.txt" *base-path* backup) content)) 64 | 65 | (defn new-month? 66 | "Predicate: Given the contents of this backup's checkMonth file, are 67 | we creating the first back up of this month?" 68 | [last] 69 | (let [now (get-current-month)] 70 | (not= now last))) 71 | 72 | (defn delete-backup 73 | "Remove the current named backup. This is normally done when we are 74 | starting the first backup of the month." 75 | [backup] 76 | (let [target (format "%s/%s" *base-path* backup)] 77 | (println "Removing: " target) 78 | (fs/delete-tree target))) 79 | 80 | (defn get-backup-usage 81 | "How much disk space is this backup using?" 82 | [backup] 83 | (let [path (format "%s/%s" *base-path* backup) 84 | fsize (sh "du" "-sb" path) 85 | outsize (first (string/split (:out fsize) #"\s"))] 86 | (println "Size of current backup: " outsize) 87 | (bigint (string/trim outsize)))) 88 | 89 | (defn check-month 90 | "Check whether we've started a new month. If we have, create a new 91 | backup from scratch." 92 | [backup] 93 | (let [check (io/as-file (format "%s/checkMonth_%s.txt" *base-path* backup)) 94 | last (if (.exists check) (slurp check) nil)] 95 | (when (new-month? last) 96 | (println (format "Starting a new monthly backup set for %s" (format "%s/%s" *base-path* backup))) 97 | (let [backupdir (io/as-file (format "%s/%s" *base-path* backup))] 98 | (when (.exists backupdir) 99 | (println "Existing backup found, so removing..." ) 100 | (delete-backup backup)) 101 | (io/make-parents (format "%s/.keep" (.getPath backupdir)))) 102 | (write-check-month-file (get-current-month) backup)))) 103 | 104 | (defn make-hard-link 105 | "Make a hard link of the current back up." 106 | [backup bdir] 107 | (let [linkto (format "%s/old/%s" *base-path* bdir) 108 | linkfrom (format "%s/%s/" *base-path* backup)] 109 | (io/make-parents (io/as-file linkto)) 110 | (link linkfrom linkto))) 111 | 112 | (defn oldest-dir 113 | "Find the oldest (least most recently modified) directory in parent." 114 | [parent] 115 | (let [dirs (.listFiles (io/as-file parent)) 116 | sorted (sort-by #(.lastModified %) dirs)] 117 | (first sorted))) 118 | 119 | (defn delete-oldest-backup 120 | "Find the oldest backup hard linked in /old and remove it." 121 | [] 122 | (let [dir (.getName (oldest-dir (format "%s/old" *base-path*)))] 123 | (println "Oldest backup: " dir) 124 | (if (not (nil? dir)) 125 | (sh "bash" "-c" (format "rm -rf %s/old/%s" *base-path* dir)) 126 | (throw (ex-info "Could not remove any more old backups!" {:base-path *base-path*}))))) 127 | 128 | (defn check-free 129 | "Check the free space on the backup device. If it isn't at 130 | least twice the size of the last (current) backup, delete the oldest 131 | backup and try again. Repeat until enough space." 132 | [backup] 133 | (let [curr-used (get-backup-usage backup) 134 | est-need (* curr-used 2)] 135 | (println "The current back up is using " curr-used) 136 | (println "We're estimating that we need: " est-need) 137 | (loop [curr-free (.getFreeSpace (io/as-file *base-path*))] 138 | (println "Current free space on this device: " curr-free) 139 | (if (> curr-free est-need) 140 | true 141 | (do 142 | (println "Not enough disk space available, so removing the oldest backup.") 143 | (delete-oldest-backup) 144 | (recur (.getFreeSpace (io/as-file *base-path*)))))))) 145 | 146 | (defn rsync! 147 | "The actual rsync of files from somewhere, to somewhere else. This 148 | returns a map of the :exit code, standard output (:out) and any :err 149 | output." 150 | [backup-from backup-to] 151 | (let [rsync-command (into [] (conj *rsync-command* backup-from (format "%s/%s" *base-path* backup-to)))] 152 | (println "Starting rsync: " (string/join " " rsync-command)) 153 | (apply sh rsync-command))) 154 | 155 | (defn -main 156 | [] 157 | (let [[backup-from backup-to] *command-line-args*] 158 | (when (or (not backup-from) (not backup-to)) 159 | (println "Usage: ") 160 | (System/exit 1)) 161 | (println (format "Starting backup of %s to %s on %s" backup-from backup-to (.toString (LocalDateTime/now)))) 162 | (check-month backup-to) 163 | (let [result (retry #(rsync! backup-from backup-to) #(= 0 (:exit %)) 3)] 164 | (if (= 0 (:exit result)) 165 | (do 166 | (println (:out result)) 167 | (make-hard-link backup-to (format "%s-%s" (.format (LocalDateTime/now) date-time-formatter) backup-to)) 168 | (check-free backup-to) 169 | (println (format "Successfully finished backup of %s at %s" backup-from (.toString (LocalDateTime/now))))) 170 | (do 171 | (println (format "The backup of %s ended in an error: %s" backup-from (:err result))) 172 | (println "Not making a hard link or checking free space."))) 173 | (System/exit (:exit result))))) 174 | 175 | (when (= *file* (System/getProperty "babashka.file")) 176 | (-main)) 177 | 178 | 179 | (comment 180 | (import (java.time.format DateTimeFormatter)) 181 | (import (java.time LocalDateTime)) 182 | (require '[clojure.java.io :as io]) 183 | (require '[clojure.java.shell :refer [sh]]) 184 | (def *base-path* "/home/eamonn/backup-test") 185 | ) 186 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 4 | 5 | 1. DEFINITIONS 6 | 7 | "Contribution" means: 8 | 9 | a) in the case of the initial Contributor, the initial code and 10 | documentation distributed under this Agreement, and 11 | 12 | b) in the case of each subsequent Contributor: 13 | 14 | i) changes to the Program, and 15 | 16 | ii) additions to the Program; 17 | 18 | where such changes and/or additions to the Program originate from and are 19 | distributed by that particular Contributor. A Contribution 'originates' from 20 | a Contributor if it was added to the Program by such Contributor itself or 21 | anyone acting on such Contributor's behalf. Contributions do not include 22 | additions to the Program which: (i) are separate modules of software 23 | distributed in conjunction with the Program under their own license 24 | agreement, and (ii) are not derivative works of the Program. 25 | 26 | "Contributor" means any person or entity that distributes the Program. 27 | 28 | "Licensed Patents" mean patent claims licensable by a Contributor which are 29 | necessarily infringed by the use or sale of its Contribution alone or when 30 | combined with the Program. 31 | 32 | "Program" means the Contributions distributed in accordance with this 33 | Agreement. 34 | 35 | "Recipient" means anyone who receives the Program under this Agreement, 36 | including all Contributors. 37 | 38 | 2. GRANT OF RIGHTS 39 | 40 | a) Subject to the terms of this Agreement, each Contributor hereby grants 41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 42 | reproduce, prepare derivative works of, publicly display, publicly perform, 43 | distribute and sublicense the Contribution of such Contributor, if any, and 44 | such derivative works, in source code and object code form. 45 | 46 | b) Subject to the terms of this Agreement, each Contributor hereby grants 47 | Recipient a non-exclusive, worldwide, royalty-free patent license under 48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 49 | transfer the Contribution of such Contributor, if any, in source code and 50 | object code form. This patent license shall apply to the combination of the 51 | Contribution and the Program if, at the time the Contribution is added by the 52 | Contributor, such addition of the Contribution causes such combination to be 53 | covered by the Licensed Patents. The patent license shall not apply to any 54 | other combinations which include the Contribution. No hardware per se is 55 | licensed hereunder. 56 | 57 | c) Recipient understands that although each Contributor grants the licenses 58 | to its Contributions set forth herein, no assurances are provided by any 59 | Contributor that the Program does not infringe the patent or other 60 | intellectual property rights of any other entity. Each Contributor disclaims 61 | any liability to Recipient for claims brought by any other entity based on 62 | infringement of intellectual property rights or otherwise. As a condition to 63 | exercising the rights and licenses granted hereunder, each Recipient hereby 64 | assumes sole responsibility to secure any other intellectual property rights 65 | needed, if any. For example, if a third party patent license is required to 66 | allow Recipient to distribute the Program, it is Recipient's responsibility 67 | to acquire that license before distributing the Program. 68 | 69 | d) Each Contributor represents that to its knowledge it has sufficient 70 | copyright rights in its Contribution, if any, to grant the copyright license 71 | set forth in this Agreement. 72 | 73 | 3. REQUIREMENTS 74 | 75 | A Contributor may choose to distribute the Program in object code form under 76 | its own license agreement, provided that: 77 | 78 | a) it complies with the terms and conditions of this Agreement; and 79 | 80 | b) its license agreement: 81 | 82 | i) effectively disclaims on behalf of all Contributors all warranties and 83 | conditions, express and implied, including warranties or conditions of title 84 | and non-infringement, and implied warranties or conditions of merchantability 85 | and fitness for a particular purpose; 86 | 87 | ii) effectively excludes on behalf of all Contributors all liability for 88 | damages, including direct, indirect, special, incidental and consequential 89 | damages, such as lost profits; 90 | 91 | iii) states that any provisions which differ from this Agreement are offered 92 | by that Contributor alone and not by any other party; and 93 | 94 | iv) states that source code for the Program is available from such 95 | Contributor, and informs licensees how to obtain it in a reasonable manner on 96 | or through a medium customarily used for software exchange. 97 | 98 | When the Program is made available in source code form: 99 | 100 | a) it must be made available under this Agreement; and 101 | 102 | b) a copy of this Agreement must be included with each copy of the Program. 103 | 104 | Contributors may not remove or alter any copyright notices contained within 105 | the Program. 106 | 107 | Each Contributor must identify itself as the originator of its Contribution, 108 | if any, in a manner that reasonably allows subsequent Recipients to identify 109 | the originator of the Contribution. 110 | 111 | 4. COMMERCIAL DISTRIBUTION 112 | 113 | Commercial distributors of software may accept certain responsibilities with 114 | respect to end users, business partners and the like. While this license is 115 | intended to facilitate the commercial use of the Program, the Contributor who 116 | includes the Program in a commercial product offering should do so in a 117 | manner which does not create potential liability for other Contributors. 118 | Therefore, if a Contributor includes the Program in a commercial product 119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend 120 | and indemnify every other Contributor ("Indemnified Contributor") against any 121 | losses, damages and costs (collectively "Losses") arising from claims, 122 | lawsuits and other legal actions brought by a third party against the 123 | Indemnified Contributor to the extent caused by the acts or omissions of such 124 | Commercial Contributor in connection with its distribution of the Program in 125 | a commercial product offering. The obligations in this section do not apply 126 | to any claims or Losses relating to any actual or alleged intellectual 127 | property infringement. In order to qualify, an Indemnified Contributor must: 128 | a) promptly notify the Commercial Contributor in writing of such claim, and 129 | b) allow the Commercial Contributor tocontrol, and cooperate with the 130 | Commercial Contributor in, the defense and any related settlement 131 | negotiations. The Indemnified Contributor may participate in any such claim 132 | at its own expense. 133 | 134 | For example, a Contributor might include the Program in a commercial product 135 | offering, Product X. That Contributor is then a Commercial Contributor. If 136 | that Commercial Contributor then makes performance claims, or offers 137 | warranties related to Product X, those performance claims and warranties are 138 | such Commercial Contributor's responsibility alone. Under this section, the 139 | Commercial Contributor would have to defend claims against the other 140 | Contributors related to those performance claims and warranties, and if a 141 | court requires any other Contributor to pay any damages as a result, the 142 | Commercial Contributor must pay those damages. 143 | 144 | 5. NO WARRANTY 145 | 146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON 147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR 149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A 150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the 151 | appropriateness of using and distributing the Program and assumes all risks 152 | associated with its exercise of rights under this Agreement , including but 153 | not limited to the risks and costs of program errors, compliance with 154 | applicable laws, damage to or loss of data, programs or equipment, and 155 | unavailability or interruption of operations. 156 | 157 | 6. DISCLAIMER OF LIABILITY 158 | 159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 166 | OF SUCH DAMAGES. 167 | 168 | 7. GENERAL 169 | 170 | If any provision of this Agreement is invalid or unenforceable under 171 | applicable law, it shall not affect the validity or enforceability of the 172 | remainder of the terms of this Agreement, and without further action by the 173 | parties hereto, such provision shall be reformed to the minimum extent 174 | necessary to make such provision valid and enforceable. 175 | 176 | If Recipient institutes patent litigation against any entity (including a 177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 178 | (excluding combinations of the Program with other software or hardware) 179 | infringes such Recipient's patent(s), then such Recipient's rights granted 180 | under Section 2(b) shall terminate as of the date such litigation is filed. 181 | 182 | All Recipient's rights under this Agreement shall terminate if it fails to 183 | comply with any of the material terms or conditions of this Agreement and 184 | does not cure such failure in a reasonable period of time after becoming 185 | aware of such noncompliance. If all Recipient's rights under this Agreement 186 | terminate, Recipient agrees to cease use and distribution of the Program as 187 | soon as reasonably practicable. However, Recipient's obligations under this 188 | Agreement and any licenses granted by Recipient relating to the Program shall 189 | continue and survive. 190 | 191 | Everyone is permitted to copy and distribute copies of this Agreement, but in 192 | order to avoid inconsistency the Agreement is copyrighted and may only be 193 | modified in the following manner. The Agreement Steward reserves the right to 194 | publish new versions (including revisions) of this Agreement from time to 195 | time. No one other than the Agreement Steward has the right to modify this 196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 197 | Eclipse Foundation may assign the responsibility to serve as the Agreement 198 | Steward to a suitable separate entity. Each new version of the Agreement will 199 | be given a distinguishing version number. The Program (including 200 | Contributions) may always be distributed subject to the version of the 201 | Agreement under which it was received. In addition, after a new version of 202 | the Agreement is published, Contributor may elect to distribute the Program 203 | (including its Contributions) under the new version. Except as expressly 204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 205 | licenses to the intellectual property of any Contributor under this 206 | Agreement, whether expressly, by implication, estoppel or otherwise. All 207 | rights in the Program not expressly granted under this Agreement are 208 | reserved. 209 | 210 | This Agreement is governed by the laws of the State of New York and the 211 | intellectual property laws of the United States of America. No party to this 212 | Agreement will bring a legal action under this Agreement more than one year 213 | after the cause of action arose. Each party waives its rights to a jury trial 214 | in any resulting litigation. 215 | --------------------------------------------------------------------------------