Duply-code

From duply
Jump to: navigation, search

duply sourcecode

duply's svn repository is not the most recent source for the code. Usually the svn only gets updated on releases. But not always. Development snapshots are taken daily. These are not guaranteed to work, but might contain unreleased fixes. Check the snapshot's changelog header accordingly.

SVN access

Browse the repository

http://ftplicity.svn.sourceforge.net/viewvc/ftplicity/duply/trunk/

SVN access

svn co https://ftplicity.svn.sourceforge.net/svnroot/ftplicity/duply/trunk duply

SVN Log

http://ftplicity.svn.sourceforge.net/viewvc/ftplicity/duply/?view=log

Latest Development Snapshot

mod time 2018-11-17

plain/text -> http://duply.net/tmp/duply.sh

  1. #!/usr/bin/env bash
  2. #
  3. ################################################################################
  4. # duply (grown out of ftplicity), is a shell front end to duplicity that #
  5. # simplifies the usage by managing settings for backup jobs in profiles. #
  6. # It supports executing multiple commands in a batch mode to enable single #
  7. # line cron entries and executes pre/post backup scripts. #
  8. # Since version 1.5.0 all duplicity backends are supported. Hence the name #
  9. # changed from ftplicity to duply. #
  10. # See http://duply.net or http://ftplicity.sourceforge.net/ for more info. #
  11. # (c) 2006 Christiane Ruetten, Heise Zeitschriften Verlag, Germany #
  12. # (c) 2008-2018 Edgar Soldin (changes since version 1.3) #
  13. ################################################################################
  14. # LICENSE: #
  15. # This program is licensed under GPLv2. #
  16. # Please read the accompanying license information in gpl.txt. #
  17. ################################################################################
  18. # TODO/IDEAS/KNOWN PROBLEMS:
  19. # - possibility to restore time frames (incl. deleted files)
  20. # realizable by listing each backup and restore from
  21. # oldest to the newest, problem: not performant
  22. # - search file in all backups function and show available
  23. # versions with backups date (list old avail since 0.6.06)
  24. # - edit profile opens conf file in vi
  25. # - implement log-fd interpretation
  26. # - add a duplicity option check against the options pending
  27. # deprecation since 0.5.10 namely --time-separator
  28. # --short-filenames
  29. # --old-filenames
  30. # - add 'exclude_<command>' list usage eg. exclude_verify
  31. # - featreq 25: a download/install duplicity option
  32. # - hint on install software if a piece is missing
  33. # - import/export profile from/to .tgz function !!!
  34. #
  35. # CHANGELOG:
  36. # 2.2 ()
  37. # - featreq 44: implement grouping for batch commands
  38. # new separators are [] (square brackets) or groupIn/groupOut
  39. # command 'backup' translates now to [pre_bkp_post] to be skipped as
  40. # one block in case a condition was set in the batch instruction
  41. #
  42. # 2.1 (23.07.2018)
  43. # - be more verbose when duplicity version detection fails
  44. # - using info shows python binary's path for easier identification now
  45. # - reworked python interpreter handling, it's either
  46. # configured per PYTHON var
  47. # unconfigured, parsed from duplicity shebang
  48. # or set to current duplicity default 'python2' (was 'python' until now)
  49. # - do not quotewrap strings because of slashes (eg. paths) anymore
  50. # - bugfix: improved in/exclude stripping from conf DUPL_PARAMS
  51. #
  52. # 2.0.4 (20.02.2018)
  53. # - bugfix 114: "duply usage is not current" wrt. purgeFull/Incr
  54. # - bugfix 115: typo in error message - "Not GPG_KEY entries" should be "No"
  55. # - bugfix 117: no duply_ prefix when ARCH_DIR is set in conf
  56. # - bugfix debian 882159: duply: occasionally shows negative runtimes
  57. #
  58. # 2.0.3 (29.08.2017)
  59. # - bugfix: "line 2231: CMDS: bad array subscript"
  60. # - bugfix 112: "env: illegal option -- u" on MacOSX
  61. #
  62. # 2.0.2 (23.05.2017)
  63. # - bugfix: never insert creds into file:// targets
  64. # - bugfix: avail profiles hint sometimes shortend the names by one char
  65. # - bugfix 108: CMD_NEXT variable should ignore conditional commands (and, or)
  66. # - export condition before/after next/prev command as CND_PREV,CND_NEXT now
  67. # - bugfix 97: Unknown command should be ERROR, not WARNING
  68. #
  69. # 2.0.1 (16.11.2016)
  70. # - bugfix 104: Duply 2.0 sets wrong archive dir, --name was always 'duply_'
  71. #
  72. # 2.0 (27.10.2016)
  73. # made this a major version change, as we broke backward compatibility anyway
  74. # (see last change in v1.10). got complaints that rightfully pointed out
  75. # that should only come w/ a major version change. so, here we go ;)
  76. # if your backend stops working w/ this version create a new profile and
  77. # export the env vars needed as described in the comments of the conf file
  78. # directly above the SOURCE setting.
  79. # Changes:
  80. # - making sure multi spaces in TARGET survive awk processing
  81. # - new env var PROFILE exported to scripts
  82. # - fix 102: expose a unique timestamp variable for pre/post scripts
  83. # actually a featreq. exporting RUN_START nanosec unix timestamp
  84. # - fix 101: GPG_AGENT_INFO is 'bogus' (thx Thomas Harning Jr.)
  85. # - fix 96: duply cannot handle two consecutive spaces in paths
  86. #
  87. # 1.11.3 (29.5.2016)
  88. # - fix wrong "WARNING: No running gpg-agent ..." when sign key was not set
  89. #
  90. # 1.11.2 (11.2.2016)
  91. # - fix "gpg: unsafe" version print out
  92. # - bugfix 91: v1.11 [r47] broke asymmetric encryption when using GPG_KEYS_ENC
  93. # - bugfix 90: S3: TARGET_USER/PASS have no effect, added additional
  94. # documentation about needed env vars to template conf file
  95. #
  96. # 1.11.1 (18.12.2015)
  97. # - bugfix 89: "Duply has trouble with PYTHON-interpreter" on OSX homebrew
  98. # - reverted duply's default PYTHON to 'python'
  99. #
  100. # 1.11 (24.11.2015)
  101. # - remove obsolete --ssh-askpass routine
  102. # - add PYTHON conf var to allow global override of used python interpreter
  103. # - enforced usage of "python2" in PATH as default interpreter for internal
  104. # use _and_ to run duplicity (setup.py changed the shebang to the fixed
  105. # path /usr/bin/python until 0.7.05, which we circumvent this way)
  106. # - featreq 36: support gpg-connect-agent as a means to detect if an agent is
  107. # running (thx Thomas Harning Jr.), used gpg-agent for detection though
  108. # - quotewrapped run_cmd parameters to protect it from spaces eg. in TMP path
  109. # - key export routine respects gpg-agent usage now
  110. #
  111. # 1.10.1 (19.8.2015)
  112. # - bugfix 86: Duply+Swift outputs warning
  113. # - bugfix 87: Swift fails without BACKEND_URL
  114. #
  115. # 1.10 (31.7.2015)
  116. # - featreq 37: busybox issues - fix awk, grep version detection,
  117. # fix grep failure because --color=never switch is unsupported
  118. # (thx Thomas Harning Jr. for reporting and helping to debug/fix it)
  119. # - bugfix 81: --exclude-globbing-filelist is deprecated since 0.7.03
  120. # (thx Joachim Wiedorn, also for maintaining the debian package)
  121. # - implemented base-/dirname as bash functions
  122. # - featreq 31 " Support for duplicity Azure backend " - ignored a
  123. # contributed patch by Scott McKenzie and instead opted for removing almost
  124. # all code that deals with special env vars required by backends.
  125. # adding and modifying these results in too much overhead so i dropped this
  126. # feature. the future alternative for users is to consult the duplicity
  127. # manpage and add the needed export definitions to the conf file.
  128. # appended a commented example to the template conf below the auth section.
  129. #
  130. # 1.9.2 (21.6.2015)
  131. # - bugfix: exporting keys with gpg2.1 works now (thx Philip Jocks)
  132. # - documented GPG_OPTS needed for gpg2.1 to conf template (thx Troy Engel)
  133. # - bugfix 82: GREP_OPTIONS=--color=always disrupted time calculation
  134. # - added GPG conf var (see conf template for details)
  135. # - added grep version output as it is an integral needed binary
  136. # - added PYTHONPATH printout in version output
  137. #
  138. # 1.9.1 (13.10.2014)
  139. # - export CMD_ERR now for scripts to detect if CMD_PREV failed/succeeded
  140. # - bugfix: CMD_PREV contained command even if it was skipped
  141. #
  142. # 1.9.0 (24.8.2014)
  143. # - bugfix: env vars were not exported when external script was executable
  144. # - rework GPG_KEY handling, allow virtually anything now (uid, keyid etc.)
  145. # see gpg manpage, section "How to specify a user ID"
  146. # let gpg complain when the delivered values are invalid for whatever reason
  147. # - started to rework tmp space checking, exposed folder & writable check
  148. # TODO: reimplement enough file space available checking
  149. #
  150. # 1.8.0 (13.7.2014)
  151. # - add command verifyPath to expose 'verify --file-to-restore' action
  152. # - add time parameter support to verify command
  153. # - add section time formats to usage output
  154. #
  155. # 1.7.4 (24.6.2014)
  156. # - remove ubuntu one support, service is discontinued
  157. # - featreq 31: add authenticated swift (contributed by Justus Seifert)
  158. #
  159. # 1.7.3 (3.4.2014)
  160. # - bugfix: test routines, gpg2 asked for passphrase although GPG_PW was set
  161. #
  162. # 1.7.2 (1.4.2014 "April,April")
  163. # - bugfix: debian Bug#743190 "duply no longer allows restoration without
  164. # gpg passphrase in conf file"
  165. # GPG_AGENT_INFO env var is now needed to trigger --use-agent
  166. # - bugfix: gpg keyenc test routines didn't work if GPG_PW was not set
  167. #
  168. # 1.7.1 (30.3.2014)
  169. # - bugfix: purge-* commands renamed to purgeFull, purgeIncr due to
  170. # incompatibility with new minus batch separator
  171. #
  172. # 1.7.0 (20.3.2014)
  173. # - disabled gpg key id plausibility check, too many valid possibilities
  174. # - featreq 7 "Halt if precondition fails":
  175. # added and(+), or(-) batch command(separator) support
  176. # - featreq 26 "pre/post script with shebang line":
  177. # if a script is flagged executable it's executed in a subshell
  178. # now as opposed to sourced to bash, which is the default
  179. # - bugfix: do not check if dpbx, swift credentials are set anymore
  180. # - bugfix: properly escape profile name, archdir if used as arguments
  181. # - add DUPL_PRECMD conf setting for use with e.g. trickle
  182. #
  183. # 1.6.0 (1.1.2014)
  184. # - support gs backend
  185. # - support dropbox backend
  186. # - add gpg-agent support to gpg test routines
  187. # - autoenable --use-agent if passwords were not defined in config
  188. # - GPG_OPTS are now honored everywhere, keyrings or complete gpg
  189. # homedir can thus be configured to be located anywhere
  190. # - always import both secret and public key if avail from config profile
  191. # - new explanatory comments in initial exclude file
  192. # - bugfix 7: Duply only imports one key at a time
  193. #
  194. # 1.5.11 (19.07.2013)
  195. # - purge-incr command for remove-all-inc-of-but-n-full feature added
  196. # patch provided by Moritz Augsburger, thanks!
  197. # - documented version command in man page
  198. #
  199. # 1.5.10 (26.03.2013)
  200. # - minor indent and documentation fixes
  201. # - bugfix: exclude filter failed on ubuntu, mawk w/o posix char class support
  202. # - bugfix: fix url_decoding generally and for python3
  203. # - bugfix 3609075: wrong script results in status line (thx David Epping)
  204. #
  205. # 1.5.9 (22.11.2012)
  206. # - bugfix 3588926: filter --exclude* params for restore/fetch ate too much
  207. # - restore/fetch now also ignores --include* or --exclude='foobar'
  208. #
  209. # 1.5.8 (26.10.2012)
  210. # - bugfix 3575487: implement proper cloud files support
  211. #
  212. # 1.5.7 (10.06.2012)
  213. # - bugfix 3531450: Cannot use space in target URL (file:///) anymore
  214. #
  215. # 1.5.6 (24.5.2012)
  216. # - commands purge, purge-full have no default value anymore for security
  217. # reasons; instead max value can be given via cmd line or must be set
  218. # in profile; else an error is shown.
  219. # - minor man page modifications
  220. #
  221. # versioning scheme will be simplified to [major].[minor].[patch] version
  222. # with the next version raise
  223. #
  224. # 1.5.5.5 (4.2.2012)
  225. # - bugfix 3479605: SEL context confused profile folder's permission check
  226. # - colon ':' in url passphrase got ignored, added python driven url_decoding
  227. # for user & pass to better process special chars
  228. #
  229. # 1.5.5.4 (16.10.2011)
  230. # - bugfix 3421268: SFTP passwords from conf ignored and always prompted for
  231. # - add support for separate sign passphrase (needs duplicity 0.6.14+)
  232. #
  233. # 1.5.5.3 (1.10.2011)
  234. # - bugfix 3416690: preview threw echo1 error
  235. # - fix unknown cmds error usage & friends if more than 2 params were given
  236. #
  237. # 1.5.5.2 (23.9.2011)
  238. # - bugfix 3409643: ssh key auth did ask for passphrase (--ssh-askpass ?)
  239. # - bugfix: mawk does not support \W and did not split multikey definitions
  240. # - all parameters should survive single (') and double (") quotes now
  241. #
  242. # 1.5.5.1 (7.6.2011)
  243. # - featreq 3311881: add ftps as supported by duplicity 0.6.13 (thx mape2k)
  244. # - bugfix 3312208: signing detection broke symmetric gpg test routine
  245. #
  246. # 1.5.5 (2.5.2011)
  247. # - bugfix: fetch problem with space char in path, escape all params
  248. # containing non word chars
  249. # - list available profiles, if given profile cannot be found
  250. # - added --use-agent configuration hint
  251. # - bugfix 3174133: --exclude* params in conf DUPL_PARAMS broke
  252. # fetch/restore
  253. # - version command now prints out 'using installed' info
  254. # - featreq 3166169: autotrust imported keys, based on code submitted by
  255. # Martin Ellis - imported keys are now automagically trusted ultimately
  256. # - new txt2man feature to create manpages for package maintainers
  257. #
  258. # 1.5.4.2 (6.1.2011)
  259. # - new command changelog
  260. # - bugfix 3109884: freebsd awk segfaulted on printf '%*', use print again
  261. # - bugfix: freebsd awk hangs on 'awk -W version'
  262. # - bugfix 3150244: mawk does not know '--version'
  263. # - minor help text improvements
  264. # - new env vars CMD_PREV,CMD_NEXT replacing CMD env var for scripts
  265. #
  266. # 1.5.4.1 (4.12.2010)
  267. # - output awk, python, bash version now in prolog
  268. # - shebang uses /usr/bin/env now for freebsd compatibility,
  269. # bash not in /bin/bash
  270. # - new --disable-encryption parameter,
  271. # to override profile encr settings for one run
  272. # - added exclude-if-present setting to conf template
  273. # - bug 3126972: GPG_PW only needed for signing/symmetric encryption
  274. # (even though duplicity still needs it)
  275. #
  276. # 1.5.4 (15.11.2010)
  277. # - as of 1.5.3 already, new ARCH_DIR config option
  278. # - multiple key support
  279. # - ftplicity-Feature Requests-2994929: separate encryption and signing key
  280. # - key signing of symmetric encryption possible (duplicity patch committed)
  281. # - gpg tests disable switch
  282. # - gpg tests now previewable and more intelligent
  283. #
  284. # 1.5.3 (1.11.2010)
  285. # - bugfix 3056628: improve busybox compatibility, grep did not have -m param
  286. # - bugfix 2995408: allow empty password for PGP key
  287. # - bugfix 2996459: Duply erroneously escapes '-' symbol in username
  288. # - url_encode function is now pythonized
  289. # - rsync uses FTP_PASSWORD now if duplicity 0.6.10+ , else issue warning
  290. # - feature 3059262: Make pre and post aware of parameters,
  291. # internal parameters + CMD of pre or post
  292. #
  293. # 1.5.2.3 (16.4.2010)
  294. # - bugfix: date again, should now work virtually anywhere
  295. #
  296. # 1.5.2.2 (3.4.2010)
  297. # - minor bugfix: duplicity 0.6.8b version string now parsable
  298. # - added INSTALL.txt
  299. #
  300. # 1.5.2.1 (23.3.2010)
  301. # - bugfix: date formatting is awked now and should work on all platforms
  302. #
  303. # 1.5.2 (2.3.2010)
  304. # - bugfix: errors print to STD_ERR now, failed tasks print an error message
  305. # - added --name=duply_<profile> for duplicity 0.6.01+ to name cache folder
  306. # - simplified & cleaned profileless commands, removed second instance
  307. # - generalized separator time routines
  308. # - added support for --no-encryption (GPG_KEY='disabled'), see conf examples
  309. # - minor fixes
  310. #
  311. # 1.5.1.5 (5.2.2010)
  312. # - bugfix: added special handling of credentials for rsync, imap(s)
  313. #
  314. # 1.5.1.4 (7.1.2010)
  315. # - bugfix: nsecs defaults now to zeroes if date does not deliver [0-9]{9}
  316. # - check if ncftp binary is available if url protocol is ftp
  317. # - bugfix: duplicity output is now printed to screen directly to resolve
  318. # 'mem alloc problem' bug report
  319. # - bugfix: passwords will not be in the url anymore to solve the 'duply shows
  320. # sensitive data in process listing' bug report
  321. #
  322. # 1.5.1.3 (24.12.2009) 'merry xmas'
  323. # - bugfix: gpg pass now apostrophed to allow space and friends
  324. # - bugfix: credentials are now url encoded to allow special chars in them
  325. # a note about url encoding has been added to the conf template
  326. #
  327. # 1.5.1.2 (1.11.2009)
  328. # - bugfix: open parenthesis in password broke duplicity execution
  329. # - bugfix: ssh/scp backend does not always need credentials e.g. key auth
  330. #
  331. # 1.5.1.1 (21.09.2009)
  332. # - bugfix: fixed s3[+http] TARGET_PASS not needed routine
  333. # - bugfix: TYPO in duply 1.5.1 prohibited the use of /etc/duply
  334. # see https://sourceforge.net/tracker/index.php?func=detail&
  335. # aid=2864410&group_id=217745&atid=1041147
  336. #
  337. # 1.5.1 (21.09.2009) - duply (fka. ftplicity)
  338. # - first things first: ftplicity (being able to support all backends since
  339. # some time) will be called duply (fka. ftplicity) from now on. The addendum
  340. # is for the time being to circumvent confusion.
  341. # - bugfix: exit code is 1 (error) not 0 (success), if at least on duplicity
  342. # command failed
  343. # - s3[+http] now supported natively by translating user/pass to access_key/
  344. # secret_key environment variables needed by duplicity s3 boto backend
  345. # - bugfix: additional output lines do not confuse version check anymore
  346. # - list command supports now age parameter (patch by stefan on feature
  347. # request tracker)
  348. # - bugfix: option/param pairs are now correctly passed on to duplicity
  349. # - bugfix: s3[+http] needs no TARGET_PASS if command is read only
  350. #
  351. # 1.5.0.2 (31.07.1009)
  352. # - bugfix: insert password in target url didn't work with debian mawk
  353. # related to previous bug report
  354. #
  355. # 1.5.0.1 (23.07.2009)
  356. # - bugfix: gawk gensub dependency raised an error on debian's default mawk
  357. # replaced with match/substr command combination (bug report)
  358. # https://sf.net/tracker/?func=detail&atid=1041147&aid=2825388&
  359. # group_id=217745
  360. #
  361. # 1.5.0 (01.07.2009)
  362. # - removed ftp limitation, all duplicity backends should work now
  363. # - bugfix: date for separator failed on openwrt busybox date, added a
  364. # detecting workaround, milliseconds are not available w/ busybox date
  365. #
  366. # 1.4.2.1 (14.05.2009)
  367. # - bugfix: free temp space detection failed with lvm, fixed awk parse routine
  368. #
  369. # 1.4.2 (22.04.2009)
  370. # - gpg keys are now exported as gpgkey.[id].asc , the suffix reflects the
  371. # armored ascii nature, the id helps if the key is switched for some reason
  372. # im/export routines are updated accordingly (import is backward compatible
  373. # to the old profile/gpgkey files)
  374. # - profile argument is treated as path if it contains slashes
  375. # (for details see usage)
  376. # - non-ftplicity options (all but --preview currently) are now passed
  377. # on to duplicity
  378. # - removed need for stat in secure_conf, it is ls based now
  379. # - added profile folder readable check
  380. # - added gpg version & home info output
  381. # - awk utility availability is now checked, because it was mandatory already
  382. # - tmp space is now checked on writability and space requirement
  383. # test fails on less than 25MB or configured $VOLSIZE,
  384. # test warns if there is less than two times $VOLSIZE because
  385. # that's required for --asynchronous-upload option
  386. # - gpg functionality is tested now before executing duplicity
  387. # test drive contains encryption, decryption, comparison, cleanup
  388. # this is meant to detect non trusted or other gpg errors early
  389. # - added possibility of doing symmetric encryption with duplicity
  390. # set GPG_KEY="" or simply comment it out
  391. # - added hints in config template on the depreciation of
  392. # --short-filenames, --time-separator duplicity options
  393. #
  394. # new versioning scheme 1.4.2b => 1.4.2,
  395. # beta b's are replaced by a patch count number e.g. 1.4.2.1 will be assigned
  396. # to the first bug fixing version and 1.4.2.2 to the second and so on
  397. # also the releases will now have a release date formatted (Day.Month.Year)
  398. #
  399. # 1.4.1b1 - bugfix: ftplicity changed filesystem permission of a folder
  400. # named exactly as the profile if existing in executing dir
  401. # - improved plausibility checking of config and profile folder
  402. # - secure_conf only acts if needed and prints a warning now
  403. #
  404. # 1.4.1b - introduce status (duplicity collection-status) command
  405. # - pre/post script output printed always now, not only on errors
  406. # - new config parameter GPG_OPTS to pass gpg options
  407. # added examples & comments to profile template conf
  408. # - reworked separator times, added duration display
  409. # - added --preview switch, to preview generated command lines
  410. # - disabled MAX_AGE, MAX_FULL_BACKUPS, VERBOSITY in generated
  411. # profiles because they have reasonable defaults now if not set
  412. #
  413. # 1.4.0b1 - bugfix: incr forces incremental backups on duplicity,
  414. # therefore backup translates to pre_bkp_post now
  415. # - bugfix: new command bkp, which represents duplicity's
  416. # default action (incr or full if full_if_older matches
  417. # or no earlier backup chain is found)
  418. #
  419. # new versioning scheme 1.4 => 1.4.0, added new minor revision number
  420. # this is meant to slow down the rapid version growing but still keep
  421. # versions cleanly separated.
  422. # only additional features will raise the new minor revision number.
  423. # all releases start as beta, each bugfix release will raise the beta
  424. # count, usually new features arrive before a version 'ripes' to stable
  425. #
  426. # 1.4.0b
  427. # 1.4b - added startup info on version, time, selected profile
  428. # - added time output to separation lines
  429. # - introduced: command purge-full implements duplicity's
  430. # remove-all-but-n-full functionality (patch by unknown),
  431. # uses config variable $MAX_FULL_BACKUPS (default = 1)
  432. # - purge config var $MAX_AGE defaults to 1M (month) now
  433. # - command full does not execute pre/post anymore
  434. # use batch command pre_full_post if needed
  435. # - introduced batch mode cmd1_cmd2_etc
  436. # (in turn removed the bvp command)
  437. # - unknown/undefined command issues a warning/error now
  438. # - bugfix: version check works with 0.4.2 and older now
  439. # 1.3b3 - introduced pre/post commands to execute/debug scripts
  440. # - introduced bvp (backup, verify, purge)
  441. # - bugfix: removed need for awk gensub, now mawk compatible
  442. # 1.3b2 - removed pre/post need executable bit set
  443. # - profiles now under ~/.ftplicity as folders
  444. # - root can keep profiles in /etc/ftplicity, folder must be
  445. # created by hand, existing profiles must be moved there
  446. # - removed ftplicity in path requirement
  447. # - bugfix: bash < v.3 did not know '=~'
  448. # - bugfix: purge works again
  449. # 1.3 - introduces multiple profiles support
  450. # - modified some script errors/docs
  451. # - reordered gpg key check import routine
  452. # - added 'gpg key id not set' check
  453. # - added error_gpg (adds how to setup gpg key howto)
  454. # - bugfix: duplicity 0.4.4RC4+ parameter syntax changed
  455. # - duplicity_version_check routine introduced
  456. # - added time separator, shortnames, volsize, full_if_older
  457. # duplicity options to config file (inspired by stevie
  458. # from http://weareroot.de)
  459. # 1.1.1 - bugfix: encryption reactivated
  460. # 1.1 - introduced config directory
  461. # 1.0 - first release
  462. ################################################################################
  463.  
  464. # utility functions overriding binaries
  465.  
  466. # wrap grep to override possible env set GREP_OPTIONS=--color=always
  467. function grep {
  468. command env "GREP_OPTIONS=" grep "$@"
  469. }
  470.  
  471. # implement basename in plain bash
  472. function basename {
  473. local stripped="${1%/}"
  474. echo "${stripped##*/}"
  475. }
  476.  
  477. # implement dirname in plain bash
  478. function dirname {
  479. echo ${1%/*}
  480. }
  481.  
  482. # implement basic which in plain bash
  483. function which {
  484. type -p "$@"
  485. }
  486.  
  487. # check availability of executables via file name or file paths
  488. function lookup {
  489. local bin="$1"
  490. # look for file names in path via bash hash OR
  491. # look for executables at given relative/absolute location
  492. ( [ "${bin##*/}" == "$bin" ] && hash "$bin" 2>/dev/null ) || [ -x "$bin" ]
  493. }
  494.  
  495. # the python binary to use, exit code 0 when configured, else 1
  496. function python_binary {
  497. # if unset, parse from duplicity shebang
  498. if ! var_isset 'PYTHON'; then
  499. duplicity_python_binary_parse;
  500. echo $DUPL_PYTHON_BIN;
  501. return 1;
  502. else
  503. # tell if PYTHON was configured manually
  504. echo $PYTHON;
  505. return 0
  506. fi
  507. }
  508.  
  509. # important definitions #######################################################
  510.  
  511. ME_LONG="$0"
  512. ME="$(basename $0)"
  513. ME_NAME="${ME%%.*}"
  514. ME_VERSION="2.1"
  515. ME_WEBSITE="http://duply.net"
  516.  
  517. # default config values
  518. DEFAULT_SOURCE='/path/of/source'
  519. DEFAULT_TARGET='scheme://user[:password]@host[:port]/[/]path'
  520. DEFAULT_TARGET_USER='_backend_username_'
  521. DEFAULT_TARGET_PASS='_backend_password_'
  522. DEFAULT_GPG='gpg'
  523. DEFAULT_GPG_KEY='_KEY_ID_'
  524. DEFAULT_GPG_PW='_GPG_PASSWORD_'
  525. DEFAULT_PYTHON='python2'
  526.  
  527. # function definitions ##########################
  528.  
  529. function set_config { # sets global config vars
  530. local CONFHOME_COMPAT="$HOME/.ftplicity"
  531. local CONFHOME="$HOME/.duply"
  532. local CONFHOME_ETC_COMPAT="/etc/ftplicity"
  533. local CONFHOME_ETC="/etc/duply"
  534.  
  535. # confdir can be delivered as path (must contain /)
  536. if [ `echo $FTPLCFG | grep /` ] ; then
  537. CONFDIR=$(readlink -f $FTPLCFG 2>/dev/null || \
  538. ( echo $FTPLCFG|grep -v '^/' 1>/dev/null 2>&1 \
  539. && echo $(pwd)/${FTPLCFG} ) || \
  540. echo ${FTPLCFG})
  541. # or DEFAULT in home/.duply folder (NEW)
  542. elif [ -d "${CONFHOME}" ]; then
  543. CONFDIR="${CONFHOME}/${FTPLCFG}"
  544. # or in home/.ftplicity folder (OLD)
  545. elif [ -d "${CONFHOME_COMPAT}" ]; then
  546. CONFDIR="${CONFHOME_COMPAT}/${FTPLCFG}"
  547. warning_oldhome "${CONFHOME_COMPAT}" "${CONFHOME}"
  548. # root can put profiles under /etc/duply (NEW) if path exists
  549. elif [ -d "${CONFHOME_ETC}" ] && [ "$EUID" -eq 0 ]; then
  550. CONFDIR="${CONFHOME_ETC}/${FTPLCFG}"
  551. # root can keep profiles under /etc/ftplicity (OLD) if path exists
  552. elif [ -d "${CONFHOME_ETC_COMPAT}" ] && [ "$EUID" -eq 0 ]; then
  553. CONFDIR="${CONFHOME_ETC_COMPAT}/${FTPLCFG}"
  554. warning_oldhome "${CONFHOME_ETC_COMPAT}" "${CONFHOME_ETC}"
  555. # hmm no profile folder there, then use default for error later
  556. else
  557. CONFDIR="${CONFHOME}/${FTPLCFG}" # continue, will fail later in main
  558. fi
  559.  
  560. # remove trailing slash, get profile name etc.
  561. CONFDIR="${CONFDIR%/}"
  562. PROFILE="${CONFDIR##*/}"
  563. CONF="$CONFDIR/conf"
  564. PRE="$CONFDIR/pre"
  565. POST="$CONFDIR/post"
  566. EXCLUDE="$CONFDIR/exclude"
  567. KEYFILE="$CONFDIR/gpgkey.asc"
  568. }
  569.  
  570. function version_info { # print version information
  571. cat <<END
  572.   $ME_NAME version $ME_VERSION
  573.   ($ME_WEBSITE)
  574. END
  575. }
  576.  
  577. function version_info_using {
  578. cat <<END
  579. $(version_info)
  580.  
  581.   $(using_info)
  582. END
  583. }
  584.  
  585. function using_info {
  586. # init needed vars into global name space
  587. lookup duplicity && { duplicity_python_binary_parse; duplicity_version_get; }
  588. local NOTFOUND="INVALID"
  589. local AWK_VERSION GREP_VERSION PYTHON_RUNNER
  590. # freebsd awk (--version only), debian mawk (-W version only), deliver '' so awk does not wait for input
  591. AWK_VERSION=$( lookup awk && (awk --version 2>/dev/null || awk -W version 2>&1) | awk 'NR<=2&&tolower($0)~/(busybox|awk)/{success=1;print;exit} END{if(success<1) print "unknown"}' || echo "$NOTFOUND" )
  592. GREP_VERSION=$( lookup grep && grep --version 2>&1 | awk 'NR<=2&&tolower($0)~/(busybox|grep.*[0-9]+\.[0-9]+)/{success=1;print;exit} END{if(success<1) print "unknown"}' || echo "$NOTFOUND" )
  593. PYTHON_RUNNER=$(python_binary)
  594. local PYTHON_VERSION=$(lookup "$PYTHON_RUNNER" && "$PYTHON_RUNNER" -V 2>&1| awk '{print tolower($0);exit}' || echo "'$PYTHON_RUNNER' $NOTFOUND" )
  595. local GPG_INFO=$(gpg_avail && gpg --version 2>&1| awk '/^gpg.*[0-9\.]+$/&&length(v)<1{v=$1" "$3}/^Home:/{h=" ("$0")"}END{print v""h}' || echo "gpg $NOTFOUND")
  596. local BASH_VERSION=$(bash --version | awk 'NR==1{IGNORECASE=1;sub(/GNU bash, version[ ]+/,"",$0);print $0}')
  597. # print out
  598. echo -e "Using installed duplicity version ${DUPL_VERSION:-$NOTFOUND}\
  599. ${PYTHON_VERSION+, $PYTHON_VERSION ${PYTHON_RUNNER:+($(which "$PYTHON_RUNNER"))}${PYTHONPATH:+ 'PYTHONPATH=$PYTHONPATH'}}\
  600. ${GPG_INFO:+, $GPG_INFO}${AWK_VERSION:+, awk '${AWK_VERSION}'}${GREP_VERSION:+, grep '${GREP_VERSION}'}\
  601. ${BASH_VERSION:+, bash '${BASH_VERSION}'}."
  602. }
  603.  
  604. function usage_info { # print usage information
  605.  
  606. cat <<USAGE_EOF
  607. VERSION:
  608. $(version_info)
  609.  
  610. DESCRIPTION:
  611. Duply deals as a wrapper for the mighty duplicity magic.
  612. It simplifies running duplicity with cron or on command line by:
  613.  
  614. - keeping recurring settings in profiles per backup job
  615. - enabling batch operations eg. backup_verify+purge
  616. - executing pre/post scripts (different actions possible
  617. depending on previous or next command or it's exit status)
  618. - precondition checking for flawless duplicity operation
  619.  
  620. For each backup job one configuration profile must be created.
  621. The profile folder will be stored under '~/.${ME_NAME}/<profile>'
  622. (where ~ is the current users home directory).
  623. Hint:
  624. If the folder '/etc/${ME_NAME}' exists, the profiles for the super
  625. user root will be searched & created there.
  626.  
  627. USAGE:
  628. first time usage (profile creation):
  629. $ME <profile> create
  630.  
  631. general usage in single or batch mode (see EXAMPLES):
  632. $ME <profile> <command>[[_|+|-]<command>[_|+|-]...] [<options> ...]
  633.  
  634. For batches the conditional separators can also be written as pseudo commands
  635. and(+), or(-). See SEPARATORS for details.
  636.  
  637. Non $ME options are passed on to duplicity (see OPTIONS).
  638. All conf parameters can also be defined in the environment instead.
  639.  
  640. PROFILE:
  641. Indicated by a path or a profile name (<profile>), which is resolved
  642. to '~/.${ME_NAME}/<profile>' (~ expands to environment variable \$HOME).
  643.  
  644. Superuser root can place profiles under '/etc/${ME_NAME}'. Simply create
  645. the folder manually before running $ME_NAME as superuser.
  646. Note:
  647. Already existing profiles in root's home folder will cease to work
  648. unless they are moved to the new location manually.
  649.  
  650. example 1: $ME humbug backup
  651.  
  652. Alternatively a _path_ might be used e.g. useful for quick testing,
  653. restoring or exotic locations. Shell expansion should work as usual.
  654. Hint:
  655. The path must contain at least one path separator '/',
  656. e.g. './test' instead of only 'test'.
  657.  
  658. example 2: $ME ~/.${ME_NAME}/humbug backup
  659.  
  660. SEPARATORS:
  661. _ (underscore)
  662. neutral separator
  663. + (plus sign), _and_
  664. conditional AND
  665. the next command will only be executed if the previous succeeded
  666. - (minus sign), _or_
  667. conditional OR
  668. the next command will only be executed if the previous failed
  669. [] (square brackets), _groupIn_/_groupOut_
  670. enables grouping of commands
  671.  
  672. example:
  673. 'pre+[bkp-verify]_post' translates to
  674. 'pre_and_groupIn_bkp_or_verify_groupOut_post'
  675.  
  676. COMMANDS:
  677. usage get usage help text
  678.  
  679. and/or/groupIn/groupOut
  680. pseudo commands used in batches (see SEPARATORS above)
  681.  
  682. create creates a configuration profile
  683. backup backup with pre/post script execution (batch: [pre_bkp_post]),
  684. full (if full_if_older matches or no earlier backup is found)
  685. incremental (in all other cases)
  686. pre/post execute '<profile>/$(basename "$PRE")', '<profile>/$(basename "$POST")' scripts
  687. bkp as above but without executing pre/post scripts
  688. full force full backup
  689. incr force incremental backup
  690. list [<age>]
  691. list all files in backup (as it was at <age>, default: now)
  692. status prints backup sets and chains currently in repository
  693. verify [<age>] [--compare-data]
  694. list files changed, since age if given
  695. verifyPath <rel_path_in_bkp> <local_path> [<age>] [--compare-data]
  696. list changes of a file or folder path in backup compared to a
  697. local path, since age if given
  698. restore <target_path> [<age>]
  699. restore the complete backup to <target_path> [as it was at <age>]
  700. fetch <src_path> <target_path> [<age>]
  701. fetch single file/folder from backup [as it was at <age>]
  702. purge [<max_age>] [--force]
  703. list outdated backup files (older than \$MAX_AGE)
  704. [use --force to actually delete these files]
  705. purgeFull [<max_full_backups>] [--force]
  706. list outdated backup files (\$MAX_FULL_BACKUPS being the number of
  707. full backups and associated incrementals to keep, counting in
  708. reverse chronological order)
  709. [use --force to actually delete these files]
  710. purgeIncr [<max_fulls_with_incrs>] [--force]
  711. list outdated incremental backups (\$MAX_FULLS_WITH_INCRS being
  712. the number of full backups which associated incrementals will be
  713. kept, counting in reverse chronological order)
  714. [use --force to actually delete these files]
  715. cleanup [--force]
  716. list broken backup chain files archives (e.g. after unfinished run)
  717. [use --force to actually delete these files]
  718.  
  719. changelog print changelog / todo list
  720. txt2man feature for package maintainers - create a manpage based on the
  721. usage output. download txt2man from http://mvertes.free.fr/, put
  722. it in the PATH and run '$ME txt2man' to create a man page.
  723. version show version information of $ME_NAME and needed programs
  724.  
  725. OPTIONS:
  726. --force passed to duplicity (see commands:
  727. purge, purgeFull, purgeIncr, cleanup)
  728. --preview do nothing but print out generated duplicity command lines
  729. --disable-encryption
  730. disable encryption, overrides profile settings
  731.  
  732. TIME FORMATS:
  733. For all time related parameters like age, max_age etc.
  734. Refer to the duplicity manpage for all available formats. Here some examples:
  735. 2002-01-25T07:00:00+02:00 (full date time format string)
  736. 2002/3/5 (date string YYYY/MM/DD)
  737. 12D (interval, 12 days ago)
  738. 1h78m (interval, 1 hour 78 minutes ago)
  739.  
  740. PRE/POST SCRIPTS:
  741. Some useful internal duply variables are exported to the scripts.
  742.  
  743. PROFILE, CONFDIR, SOURCE, TARGET_URL_<PROT|HOSTPATH|USER|PASS>,
  744. GPG_<KEYS_ENC|KEY_SIGN|PW>, CMD_ERR, RUN_START,
  745. CMD_<PREV|NEXT> (previous/next command),
  746. CND_<PREV|NEXT> (condition before/after)
  747.  
  748. The CMD_* variables were introduced to allow different actions according to
  749. the command the scripts were attached to e.g. 'pre_bkp_post_pre_verify_post'
  750. will call the pre script two times, with CMD_NEXT variable set to 'bkp'
  751. on the first and to 'verify' on the second run.
  752. CMD_ERR holds the exit code of the CMD_PREV .
  753.  
  754. EXAMPLES:
  755. create profile 'humbug':
  756. $ME humbug create (don't forget to edit this new conf file)
  757. backup 'humbug' now:
  758. $ME humbug backup
  759. list available backup sets of profile 'humbug':
  760. $ME humbug status
  761. list and delete outdated backups of 'humbug':
  762. $ME humbug purge --force
  763. restore latest backup of 'humbug' to /mnt/restore:
  764. $ME humbug restore /mnt/restore
  765. restore /etc/passwd of 'humbug' from 4 days ago to /root/pw:
  766. $ME humbug fetch etc/passwd /root/pw 4D
  767. (see "duplicity manpage", section TIME FORMATS)
  768. a one line batch job on 'humbug' for cron execution:
  769. $ME humbug backup_verify_purge --force
  770. batch job to run a full backup with pre/post scripts:
  771. $ME humbug pre_full_post
  772.  
  773. FILES:
  774. in profile folder '~/.${ME_NAME}/<profile>' or '/etc/${ME_NAME}'
  775. conf profile configuration file
  776. pre,post pre/post scripts (see above for details)
  777. gpgkey.*.asc exported GPG key files
  778. exclude a globbing list of included or excluded files/folders
  779. (see "duplicity manpage", section FILE SELECTION)
  780.  
  781. $(hint_profile)
  782.  
  783. SEE ALSO:
  784. duplicity man page:
  785. duplicity(1) or http://duplicity.nongnu.org/duplicity.1.html
  786. USAGE_EOF
  787. }
  788.  
  789. # to check call 'duply txt2man | man -l -'
  790. function usage_txt2man {
  791. usage_info | \
  792. awk '/^^[^[:lower:][:space:]][^[:lower:]]+$/{gsub(/[^[:upper:]]/," ",$0)}{print}' |\
  793. txt2man -t"$(toupper "${ME_NAME}")" -s1 -r"${ME_NAME}-${ME_VERSION}" -v'User Manuals'
  794. }
  795.  
  796. function changelog {
  797. cat $ME_LONG | awk '/^#####/{on=on+1}(on==3){sub(/^#( )?/,"",$0);print}'
  798. }
  799.  
  800. function create_config {
  801. if [ ! -d "$CONFDIR" ] ; then
  802. mkdir -p "$CONFDIR" || error "Couldn't create config '$CONFDIR'."
  803. # create initial config file
  804. cat <<EOF >"$CONF"
  805. # gpg encryption settings, simple settings:
  806. # GPG_KEY='disabled' - disables encryption alltogether
  807. # GPG_KEY='<key1>[,<key2>]'; GPG_PW='pass' - encrypt with keys,
  808. # sign if secret key of key1 is available use GPG_PW for sign & decrypt
  809. # Note: you can specify keys via all methods described in gpg manpage,
  810. # section "How to specify a user ID", escape commas (,) via backslash (\)
  811. # e.g. 'Mueller, Horst', 'Bernd' -> 'Mueller\, Horst, Bernd'
  812. # as they are used to separate the entries
  813. # GPG_PW='passphrase' - symmetric encryption using passphrase only
  814. GPG_KEY='${DEFAULT_GPG_KEY}'
  815. GPG_PW='${DEFAULT_GPG_PW}'
  816. # gpg encryption settings in detail (extended settings)
  817. # the above settings translate to the following more specific settings
  818. # GPG_KEYS_ENC='<keyid1>[,<keyid2>,...]' - list of pubkeys to encrypt to
  819. # GPG_KEY_SIGN='<keyid1>|disabled' - a secret key for signing
  820. # GPG_PW='<passphrase>' - needed for signing, decryption and symmetric
  821. # encryption. If you want to deliver different passphrases for e.g.
  822. # several keys or symmetric encryption plus key signing you can use
  823. # gpg-agent. Simply make sure that GPG_AGENT_INFO is set in environment.
  824. # also see "A NOTE ON SYMMETRIC ENCRYPTION AND SIGNING" in duplicity manpage
  825. # notes on en/decryption
  826. # private key and passphrase will only be needed for decryption or signing.
  827. # decryption happens on restore and incrementals (compare archdir contents).
  828. # for security reasons it makes sense to separate the signing key from the
  829. # encryption keys. https://answers.launchpad.net/duplicity/+question/107216
  830. #GPG_KEYS_ENC='<pubkey1>,<pubkey2>,...'
  831. #GPG_KEY_SIGN='<prvkey>'
  832. # set if signing key passphrase differs from encryption (key) passphrase
  833. # NOTE: available since duplicity 0.6.14, translates to SIGN_PASSPHRASE
  834. #GPG_PW_SIGN='<signpass>'
  835.  
  836. # uncomment and set a file path or name force duply to use this gpg executable
  837. # available in duplicity 0.7.04 and above (currently unreleased 06/2015)
  838. #GPG='/usr/local/gpg-2.1/bin/gpg'
  839.  
  840. # gpg options passed from duplicity to gpg process (default='')
  841. # e.g. "--trust-model pgp|classic|direct|always"
  842. # or "--compress-algo=bzip2 --bzip2-compress-level=9"
  843. # or "--personal-cipher-preferences AES256,AES192,AES..."
  844. # or "--homedir ~/.duply" - keep keyring and gpg settings duply specific
  845. # or "--pinentry-mode loopback" - needed for GPG 2.1+ _and_
  846. # also enable allow-loopback-pinentry in your .gnupg/gpg-agent.conf
  847. #GPG_OPTS=''
  848.  
  849. # disable preliminary tests with the following setting
  850. #GPG_TEST='disabled'
  851.  
  852. # backend, credentials & location of the backup target (URL-Format)
  853. # generic syntax is
  854. # scheme://[user[:password]@]host[:port]/[/]path
  855. # eg.
  856. # sftp://bob:secret@backupserver.com//home/bob/dupbkp
  857. # for details and available backends see duplicity manpage, section URL Format
  858. # http://duplicity.nongnu.org/duplicity.1.html#sect7
  859. # BE AWARE:
  860. # some backends (cloudfiles, S3 etc.) need additional env vars to be set to
  861. # work properly, read after the TARGET definition for more details.
  862. # ATTENTION:
  863. # characters other than A-Za-z0-9.-_.~ in the URL have to be
  864. # replaced by their url encoded pendants, see
  865. # http://en.wikipedia.org/wiki/Url_encoding
  866. # if you define the credentials as TARGET_USER, TARGET_PASS below $ME
  867. # will try to url_encode them for you if the need arises.
  868. TARGET='${DEFAULT_TARGET}'
  869. # optionally the username/password can be defined as extra variables
  870. # setting them here _and_ in TARGET results in an error
  871. # ATTENTION:
  872. # there are backends that do not support the user/pass auth scheme.
  873. # prominent examples are S3, Azure, Cloudfiles. when in doubt consult the
  874. # duplicity manpage. usually there is a NOTE section explaining if and which
  875. # env vars should be set.
  876. #TARGET_USER='${DEFAULT_TARGET_USER}'
  877. #TARGET_PASS='${DEFAULT_TARGET_PASS}'
  878. # eg. for cloud files backend it might look like this (uncomment for use!)
  879. #export CLOUDFILES_USERNAME='someuser'
  880. #export CLOUDFILES_APIKEY='somekey'
  881. #export CLOUDFILES_AUTHURL ='someurl'
  882. # the following is an incomplete list (<backend>: comma separated env vars list)
  883. # Azure: AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY
  884. # Cloudfiles: CLOUDFILES_USERNAME, CLOUDFILES_APIKEY, CLOUDFILES_AUTHURL
  885. # Google Cloud Storage: GS_ACCESS_KEY_ID, GS_SECRET_ACCESS_KEY
  886. # Pydrive: GOOGLE_DRIVE_ACCOUNT_KEY, GOOGLE_DRIVE_SETTINGS
  887. # S3: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  888. # Swift: SWIFT_USERNAME, SWIFT_PASSWORD, SWIFT_AUTHURL,
  889. # SWIFT_TENANTNAME OR SWIFT_PREAUTHURL, SWIFT_PREAUTHTOKEN
  890.  
  891. # base directory to backup
  892. SOURCE='${DEFAULT_SOURCE}'
  893.  
  894. # a command that runs duplicity e.g.
  895. # shape bandwidth use via trickle
  896. # "trickle -s -u 640 -d 5120" # 5Mb up, 40Mb down"
  897. #DUPL_PRECMD=""
  898.  
  899. # override the used python interpreter, defaults to
  900. # - parsed result of duplicity's shebang or 'python2'
  901. # e.g. "python2" or "/usr/bin/python2.7"
  902. #PYTHON="python"
  903.  
  904. # exclude folders containing exclusion file (since duplicity 0.5.14)
  905. # Uncomment the following two lines to enable this setting.
  906. #FILENAME='.duplicity-ignore'
  907. #DUPL_PARAMS="\$DUPL_PARAMS --exclude-if-present '\$FILENAME'"
  908.  
  909. # Time frame for old backups to keep, Used for the "purge" command.
  910. # see duplicity man page, chapter TIME_FORMATS)
  911. #MAX_AGE=1M
  912.  
  913. # Number of full backups to keep. Used for the "purgeFull" command.
  914. # See duplicity man page, action "remove-all-but-n-full".
  915. #MAX_FULL_BACKUPS=1
  916.  
  917. # Number of full backups for which incrementals will be kept for.
  918. # Used for the "purgeIncr" command.
  919. # See duplicity man page, action "remove-all-inc-of-but-n-full".
  920. #MAX_FULLS_WITH_INCRS=1
  921.  
  922. # activates duplicity --full-if-older-than option (since duplicity v0.4.4.RC3)
  923. # forces a full backup if last full backup reaches a specified age, for the
  924. # format of MAX_FULLBKP_AGE see duplicity man page, chapter TIME_FORMATS
  925. # Uncomment the following two lines to enable this setting.
  926. #MAX_FULLBKP_AGE=1M
  927. #DUPL_PARAMS="\$DUPL_PARAMS --full-if-older-than \$MAX_FULLBKP_AGE "
  928.  
  929. # sets duplicity --volsize option (available since v0.4.3.RC7)
  930. # set the size of backup chunks to VOLSIZE MB instead of the default 25MB.
  931. # VOLSIZE must be number of MB's to set the volume size to.
  932. # Uncomment the following two lines to enable this setting.
  933. #VOLSIZE=50
  934. #DUPL_PARAMS="\$DUPL_PARAMS --volsize \$VOLSIZE "
  935.  
  936. # verbosity of output (error 0, warning 1-2, notice 3-4, info 5-8, debug 9)
  937. # default is 4, if not set
  938. #VERBOSITY=5
  939.  
  940. # temporary file space. at least the size of the biggest file in backup
  941. # for a successful restoration process. (default is '/tmp', if not set)
  942. #TEMP_DIR=/tmp
  943.  
  944. # Modifies archive-dir option (since 0.6.0) Defines a folder that holds
  945. # unencrypted meta data of the backup, enabling new incrementals without the
  946. # need to decrypt backend metadata first. If empty or deleted somehow, the
  947. # private key and it's password are needed.
  948. # NOTE: This is confidential data. Put it somewhere safe. It can grow quite
  949. # big over time so you might want to put it not in the home dir.
  950. # default '~/.cache/duplicity/duply_<profile>/'
  951. # if set '\${ARCH_DIR}/<profile>'
  952. #ARCH_DIR=/some/space/safe/.duply-cache
  953.  
  954. # DEPRECATED setting
  955. # sets duplicity --time-separator option (since v0.4.4.RC2) to allow users
  956. # to change the time separator from ':' to another character that will work
  957. # on their system. HINT: For Windows SMB shares, use --time-separator='_'.
  958. # NOTE: '-' is not valid as it conflicts with date separator.
  959. # ATTENTION: only use this with duplicity < 0.5.10, since then default file
  960. # naming is compatible and this option is pending depreciation
  961. #DUPL_PARAMS="\$DUPL_PARAMS --time-separator _ "
  962.  
  963. # DEPRECATED setting
  964. # activates duplicity --short-filenames option, when uploading to a file
  965. # system that can't have filenames longer than 30 characters (e.g. Mac OS 8)
  966. # or have problems with ':' as part of the filename (e.g. Microsoft Windows)
  967. # ATTENTION: only use this with duplicity < 0.5.10, later versions default file
  968. # naming is compatible and this option is pending depreciation
  969. #DUPL_PARAMS="\$DUPL_PARAMS --short-filenames "
  970.  
  971. # more duplicity command line options can be added in the following way
  972. # don't forget to leave a separating space char at the end
  973. #DUPL_PARAMS="\$DUPL_PARAMS --put_your_options_here "
  974.  
  975. EOF
  976.  
  977. # create initial exclude file
  978. cat <<EOF >"$EXCLUDE"
  979. # although called exclude, this file is actually a globbing file list
  980. # duplicity accepts some globbing patterns, even including ones here
  981. # here is an example, this incl. only 'dir/bar' except it's subfolder 'foo'
  982. # - dir/bar/foo
  983. # + dir/bar
  984. # - **
  985. # for more details see duplicity manpage, section File Selection
  986. # http://duplicity.nongnu.org/duplicity.1.html#sect9
  987.  
  988. EOF
  989.  
  990. # Hints on first usage
  991. cat <<EOF
  992.  
  993. Congratulations. You just created the profile '$FTPLCFG'.
  994. The initial config file has been created as
  995. '$CONF'.
  996. You should now adjust this config file to your needs.
  997.  
  998. $(hint_profile)
  999.  
  1000. EOF
  1001. fi
  1002.  
  1003. }
  1004.  
  1005. # used in usage AND create_config
  1006. function hint_profile {
  1007. cat <<EOF
  1008. IMPORTANT:
  1009.   Copy the _whole_ profile folder after the first backup to a safe place.
  1010.   It contains everything needed to restore your backups. You will need
  1011.   it if you have to restore the backup from another system (e.g. after a
  1012.   system crash). Keep access to these files restricted as they contain
  1013.   _all_ informations (gpg data, ftp data) to access and modify your backups.
  1014.  
  1015.   Repeat this step after _all_ configuration changes. Some configuration
  1016.   options are crucial for restoration.
  1017.  
  1018. EOF
  1019. }
  1020.  
  1021. function separator {
  1022. echo "--- $@ ---"
  1023. }
  1024.  
  1025. function inform {
  1026. echo -e "\nINFO:\n\n$@\n"
  1027. }
  1028.  
  1029. function warning {
  1030. echo -e "\nWARNING:\n\n$@\n"
  1031. }
  1032.  
  1033. function warning_oldhome {
  1034. local old=$1 new=$2
  1035. warning " ftplicity changed name to duply since you created your profiles.
  1036. Please rename the old folder
  1037. '$old'
  1038. to
  1039. '$new'
  1040. and this warning will disappear.
  1041. If you decide not to do so profiles will _only_ work from the old location."
  1042. }
  1043.  
  1044. function error_print {
  1045. echo -e "$@" >&2
  1046. }
  1047.  
  1048. function error {
  1049. error_print "\nSorry. A fatal ERROR occured:\n\n$@\n"
  1050. exit -1
  1051. }
  1052.  
  1053. function error_gpg {
  1054. [ -n "$2" ] && local hint="\n $2\n\n "
  1055.  
  1056. error "$1
  1057.  
  1058. Hint${hint:+s}:
  1059. ${hint}Maybe you have not created a gpg key yet (e.g. gpg --gen-key)?
  1060. Don't forget the used _password_ as you will need it.
  1061. When done enter the 8 digit id & the password in the profile conf file.
  1062.  
  1063. The key id can be found doing a 'gpg --list-keys'. In the example output
  1064. below the key id would be FFFFFFFF for the public key.
  1065.  
  1066. pub 1024D/FFFFFFFF 2007-12-17
  1067. uid duplicity
  1068. sub 2048g/899FE27F 2007-12-17
  1069. "
  1070. }
  1071.  
  1072. function error_gpg_key {
  1073. local KEY_ID="$1"
  1074. local KIND="$2"
  1075. error_gpg "${KIND} gpg key '${KEY_ID}' cannot be found." \
  1076. "Doublecheck if the above key is listed by 'gpg --list-keys' or available
  1077. as gpg key file '$(basename "$(gpg_keyfile "${KEY_ID}")")' in the profile folder.
  1078. If not you can put it there and $ME_NAME will autoimport it on the next run.
  1079. Alternatively import it manually as the user you plan to run $ME_NAME with."
  1080. }
  1081.  
  1082. function error_gpg_test {
  1083. [ -n "$2" ] && local hint="\n $2\n\n "
  1084.  
  1085. error "$1
  1086.  
  1087. Hint${hint:+s}:
  1088. ${hint}This error means that gpg is probably misconfigured or not working
  1089. correctly. The error message above should help to solve the problem.
  1090. However, if for some reason $ME_NAME should misinterpret the situation you
  1091. can define GPG_TEST='disabled' in the conf file to bypass the test.
  1092. Please do not forget to report the bug in order to resolve the problem
  1093. in future versions of $ME_NAME.
  1094. "
  1095. }
  1096.  
  1097. function error_path {
  1098. error "$@
  1099. PATH='$PATH'
  1100. "
  1101. }
  1102.  
  1103. function error_to_string {
  1104. [ -n "$1" ] && [ "$1" -eq 0 ] && echo "OK" || echo "FAILED 'code $1'"
  1105. }
  1106.  
  1107. function duplicity_version_get {
  1108. # nothing to do, just print
  1109. var_isset DUPL_VERSION && return
  1110.  
  1111. local DUPL_VERSION_OUT DUPL_VERSION_AWK PYTHON_BIN CMD='duplicity'
  1112. # only run with a user specific python if configured (running by default
  1113. # breaks homebrew as they place a shell wrapper for duplicity in path)
  1114. PYTHON_BIN="$(python_binary)" &&\
  1115. CMD="$(qw "$PYTHON_BIN") $(which $CMD)"
  1116. CMD="$CMD --version 2>&1"
  1117. DUPL_VERSION_OUT=$(eval "$CMD")
  1118. DUPL_VERSION=`echo $DUPL_VERSION_OUT | awk '/^duplicity /{print $2; exit;}'`
  1119. #DUPL_VERSION='0.7.03' #'0.6.08b' #,0.4.4.RC4,0.6.08b
  1120. DUPL_VERSION_VALUE=0
  1121. DUPL_VERSION_AWK=$(awk -v v="$DUPL_VERSION" 'BEGIN{
  1122. if (match(v,/[^\.0-9]+[0-9]*$/)){
  1123. rest=substr(v,RSTART,RLENGTH);v=substr(v,0,RSTART-1);}
  1124. if (pos=match(rest,/RC([0-9]+)$/)) rc=substr(rest,pos+2)
  1125. split(v,f,"[. ]"); if(f[1]f[2]f[3]~/^[0-9]+$/) vvalue=f[1]*10000+f[2]*100+f[3]; else vvalue=0
  1126. print "#"v"_"rest"("rc"):"f[1]"-"f[2]"-"f[3]
  1127. print "DUPL_VERSION_VALUE=\047"vvalue"\047"
  1128. print "DUPL_VERSION_RC=\047"rc"\047"
  1129. print "DUPL_VERSION_SUFFIX=\047"rest"\047"
  1130. }')
  1131. eval "$DUPL_VERSION_AWK"
  1132. #echo -e ",$DUPL_VERSION,$DUPL_VERSION_VALUE,$DUPL_VERSION_RC,$DUPL_VERSION_SUFFIX,"
  1133.  
  1134. # doublecheck findings and report error
  1135. if [ $DUPL_VERSION_VALUE -eq 0 ]; then
  1136. inform "duplicity version check failed (please report, this is a bug)
  1137. the command
  1138. $CMD
  1139. resulted in
  1140. $DUPL_VERSION_OUT
  1141. "
  1142. elif [ $DUPL_VERSION_VALUE -le 404 ] && [ ${DUPL_VERSION_RC:-4} -lt 4 ]; then
  1143. error "The installed version $DUPL_VERSION is incompatible with $ME_NAME v$ME_VERSION.
  1144. You should upgrade your version of duplicity to at least v0.4.4RC4 or
  1145. use the older ftplicity version 1.1.1 from $ME_WEBSITE."
  1146. fi
  1147. }
  1148.  
  1149. function duplicity_version_ge {
  1150. [ "$DUPL_VERSION_VALUE" -ge "$1" ]
  1151. }
  1152.  
  1153. function duplicity_version_lt {
  1154.  ! duplicity_version_ge "$1"
  1155. }
  1156.  
  1157. # parse interpreter from duplicity shebang
  1158. function duplicity_python_binary_parse {
  1159. # cached result
  1160. ( var_isset 'PYTHON' || var_isset 'DUPL_PYTHON_BIN' ) && return
  1161.  
  1162. # parse it or warn
  1163. local DUPL_BIN=$(which duplicity)
  1164. DUPL_PYTHON_BIN=$(awk 'NR==1&&/^#!/{sub(/^#!( *\/usr\/bin\/env *)?/,""); print}' < "$DUPL_BIN")
  1165. if ! echo "$DUPL_PYTHON_BIN" | grep -q -i 'python'; then
  1166. warning "Could not parse the python interpreter used from duplicity ($DUPL_BIN). Result was '$DUPL_PYTHON_BIN'.
  1167. Will assume it is '$DEFAULT_PYTHON'."
  1168. DUPL_PYTHON_BIN="$DEFAULT_PYTHON"
  1169. fi
  1170. }
  1171.  
  1172. function run_script { # run pre/post scripts
  1173. local ERR=0
  1174. local SCRIPT="$1"
  1175. if [ ! -z "$PREVIEW" ] ; then
  1176. echo "$([ ! -x "$SCRIPT" ] && echo ". ")$SCRIPT"
  1177. elif [ -r "$SCRIPT" ] ; then
  1178. echo -n "Running '$SCRIPT' "
  1179. if [ -x "$SCRIPT" ]; then
  1180. OUT=$("$SCRIPT" 2>&1)
  1181. ERR=$?
  1182. else
  1183. OUT=$(. "$SCRIPT" 2>&1)
  1184. ERR=$?
  1185. fi
  1186. [ $ERR -eq "0" ] && echo "- OK" || echo "- FAILED (code $ERR)"
  1187. echo -en ${OUT:+"Output: $OUT\n"} ;
  1188. else
  1189. echo "Skipping n/a script '$SCRIPT'."
  1190. fi
  1191. return $ERR
  1192. }
  1193.  
  1194. function run_cmd {
  1195. # run or print escaped cmd string
  1196. local CMD_ERR=0
  1197. if [ -n "$PREVIEW" ]; then
  1198. CMD_OUT=$( echo "$@ 2>&1" )
  1199. CMD_MSG="-- Run cmd -- $CMD_MSG --\n$CMD_OUT"
  1200. elif [ -n "$CMD_DISABLED" ]; then
  1201. CMD_MSG="$CMD_MSG (DISABLED) - $CMD_DISABLED"
  1202. else
  1203. echo -n -e "$CMD_MSG"
  1204. CMD_OUT=` eval "$@" 2>&1 `
  1205. CMD_ERR=$?
  1206. if [ "$CMD_ERR" = "0" ]; then
  1207. CMD_MSG=" (OK)"
  1208. else
  1209. CMD_MSG=" (FAILED)"
  1210. fi
  1211. fi
  1212. echo -e "$CMD_MSG"
  1213. # reset
  1214. unset CMD_DISABLED CMD_MSG
  1215. return $CMD_ERR
  1216. }
  1217.  
  1218. function qw { quotewrap "$@"; }
  1219.  
  1220. function quotewrap {
  1221. local param="$@"
  1222. # quote strings having non word chars (e.g. spaces)
  1223. if echo "$param" | awk '/[^A-Za-z0-9_\.\-\/]/{exit 0}{exit 1}'; then
  1224. echo "$param" | awk '{\
  1225. gsub(/[\047]/,"\047\\\047\047",$0);\
  1226. gsub(/[\042]/,"\047\\\042\047",$0);\
  1227. print "\047"$0"\047"}'
  1228. return
  1229. fi
  1230. echo $param
  1231. }
  1232.  
  1233. function duplicity_params_global {
  1234. # already done? return
  1235. var_isset 'DUPL_PARAMS_GLOBAL' && return
  1236. local DUPL_ARG_ENC
  1237.  
  1238. # use key only if set in config, else leave it to symmetric encryption
  1239. if gpg_disabled; then
  1240. local DUPL_PARAM_ENC='--no-encryption'
  1241. else
  1242. local DUPL_PARAM_ENC=$(gpg_prefix_keyset '--encrypt-key' "${GPG_KEYS_ENC_ARRAY[@]}")
  1243. gpg_signing && local DUPL_PARAM_SIGN=$(gpg_prefix_keyset '--sign-key' "$GPG_KEY_SIGN")
  1244. # interpret password settings
  1245. var_isset 'GPG_PW' && DUPL_ARG_ENC="PASSPHRASE=$(qw "${GPG_PW}")"
  1246. var_isset 'GPG_PW_SIGN' && DUPL_ARG_ENC="${DUPL_ARG_ENC} SIGN_PASSPHRASE=$(qw "${GPG_PW_SIGN}")"
  1247. fi
  1248.  
  1249. local GPG_OPTS=${GPG_OPTS:+"--gpg-options $(qw "${GPG_OPTS}")"}
  1250.  
  1251. # set name for dupl archive folder, since 0.6.0
  1252. if duplicity_version_ge 601; then
  1253. local DUPL_ARCHDIR=''
  1254. if var_isset 'ARCH_DIR'; then
  1255. DUPL_ARCHDIR="--archive-dir $(qw "${ARCH_DIR}")"
  1256. # reuse erronously duply_ prefixed folders from bug #117
  1257. if [ -d "$ARCH_DIR/duply_${PROFILE}" ]; then
  1258. DUPL_ARCHDIR="${DUPL_ARCHDIR} --name $(qw "duply_${PROFILE}")"
  1259. else
  1260. DUPL_ARCHDIR="${DUPL_ARCHDIR} --name $(qw "${PROFILE}")"
  1261. fi
  1262. else
  1263. DUPL_ARCHDIR="--name $(qw "duply_${PROFILE}")"
  1264. fi
  1265. fi
  1266.  
  1267. DUPL_PARAMS_GLOBAL="${DUPL_ARCHDIR} ${DUPL_PARAM_ENC} \
  1268. ${DUPL_PARAM_SIGN} --verbosity '${VERBOSITY:-4}' \
  1269. ${GPG_OPTS}"
  1270.  
  1271. DUPL_VARS_GLOBAL="TMPDIR='$TEMP_DIR' \
  1272. ${DUPL_ARG_ENC}"
  1273. }
  1274.  
  1275. # function to filter the DUPL_PARAMS var from user conf
  1276. function duplicity_params_conf {
  1277. # reuse cmd var from main loop
  1278. ## in/exclude parameters are currently not supported on restores
  1279. if [ "$cmd" = "fetch" ] || [ "$cmd" = "restore" ] || [ "$cmd" = "status" ]; then
  1280. # filter exclude params from fetch/restore/status
  1281. eval "stripXcludes $DUPL_PARAMS"
  1282. return
  1283. fi
  1284.  
  1285. # nothing done, print unchanged
  1286. echo "$DUPL_PARAMS"
  1287. }
  1288.  
  1289. # strip in/exclude parameters from param string
  1290. function stripXcludes {
  1291. local STRIPNEXT OUT;
  1292. for p in "$@"; do
  1293. if [ -n "$STRIPNEXT" ]; then
  1294. unset STRIPNEXT
  1295. # strip the value of previous parameter
  1296. continue
  1297. elif echo "$p" | awk '/^\-\-(in|ex)clude(\-[a-zA-Z]+)?$/{exit 0;}{exit 1;}'; then
  1298. # strips eg. --include /foo/bar
  1299. STRIPNEXT="yes"
  1300. continue
  1301. elif echo "$p" | awk '/^\-\-(in|ex)clude(\-[a-zA-Z]+)?=/{exit 0;}{exit 1;}'; then
  1302. # strips eg. --include=/foo/bar
  1303. continue
  1304. fi
  1305.  
  1306. OUT="$OUT $(qw "$p")"
  1307. done
  1308. echo "$OUT"
  1309. }
  1310.  
  1311. function duplify { # the actual wrapper function
  1312. local PARAMSNOW DUPL_CMD DUPL_CMD_PARAMS
  1313.  
  1314. # put command (with params) first in duplicity parameters
  1315. for param in "$@" ; do
  1316. # split cmd from params (everything before splitchar --)
  1317. if [ "$param" == "--" ] ; then
  1318. PARAMSNOW=1
  1319. else
  1320. # wrap in quotes to protect from spaces
  1321. [ ! $PARAMSNOW ] && \
  1322. DUPL_CMD="$DUPL_CMD $(qw "$param")" \
  1323. || \
  1324. DUPL_CMD_PARAMS="$DUPL_CMD_PARAMS $(qw "$param")"
  1325. fi
  1326. done
  1327.  
  1328. # init global duplicity parameters same for all tasks
  1329. duplicity_params_global
  1330.  
  1331. local RUN=eval BIN=duplicity DUPL_BIN PYTHON_BIN
  1332. # run in cmd line preview mode if requested
  1333. var_isset 'PREVIEW' && RUN=echo
  1334. # try to resolve duplicity path for usage with python interpreter
  1335. DUPL_BIN=$(which "$BIN") || DUPL_BIN="$BIN"
  1336. # only run with a user specific python if configured (running by default
  1337. # breaks homebrew as they place a shell wrapper for duplicity in path)
  1338. PYTHON_BIN="$(python_binary)" &&\
  1339. BIN="$(qw "$PYTHON_BIN") $(qw "$DUPL_BIN")"
  1340.  
  1341. $RUN "${DUPL_VARS_GLOBAL} ${BACKEND_PARAMS}\
  1342. ${DUPL_PRECMD} $BIN $DUPL_CMD $DUPL_PARAMS_GLOBAL $(duplicity_params_conf)\
  1343. $GPG_USEAGENT $(gpg_custom_binary) $DUPL_CMD_PARAMS"
  1344.  
  1345. local ERR=$?
  1346. return $ERR
  1347. }
  1348.  
  1349. function secureconf { # secure the configuration dir
  1350. #PERMS=$(ls -la $(dirname $CONFDIR) | grep -e " $(basename $CONFDIR)\$" | awk '{print $1}')
  1351. local PERMS="$(ls -la "$CONFDIR/." | awk 'NR==2{print $1}')"
  1352. if [ "${PERMS/#drwx------*/OK}" != 'OK' ] ; then
  1353. chmod u+rwX,go= "$CONFDIR"; local ERR=$?
  1354. warning "The profile's folder
  1355. '$CONFDIR'
  1356. permissions are not safe ($PERMS). Secure them now. - ($(error_to_string $ERR))"
  1357. fi
  1358. }
  1359.  
  1360. # params are $1=timeformatstring (default like date output), $2=epoch seconds since 1.1.1970 (default now)
  1361. function date_fix {
  1362. local DEFAULTFORMAT='%a %b %d %H:%M:%S %Z %Y'
  1363. local date
  1364. #[ "$1" == "%N" ] && return #test the no nsec test below
  1365. # gnu date with -d @epoch
  1366. date=$(date ${2:+-d @$2} ${1:++"$1"} 2> /dev/null) && \
  1367. echo $date && return
  1368. # date bsd,osx with -r epoch
  1369. date=$(date ${2:+-r $2} ${1:++"$1"} 2> /dev/null) && \
  1370. echo $date && return
  1371. # date busybox with -d epoch -D %s
  1372. date=$(date ${2:+-d $2 -D %s} ${1:++"$1"} 2> /dev/null) && \
  1373. echo $date && return
  1374. ## some date commands do not support giving a time w/o setting it systemwide (irix,solaris,others?)
  1375. # python fallback
  1376. date=$("$(python_binary)" -c "import time;print time.strftime('${1:-$DEFAULTFORMAT}',time.localtime(${2}))" 2> /dev/null) && \
  1377. echo $date && return
  1378. # awk fallback
  1379. date=$(awk "BEGIN{print strftime(\"${1:-$DEFAULTFORMAT}\"${2:+,$2})}" 2> /dev/null) && \
  1380. echo $date && return
  1381. # perl fallback
  1382. date=$(perl -e "use POSIX qw(strftime);\$date = strftime(\"${1:-$DEFAULTFORMAT}\",localtime(${2}));print \"\$date\n\";" 2> /dev/null) && \
  1383. echo $date && return
  1384. # error
  1385. echo "ERROR"
  1386. return 1
  1387. }
  1388.  
  1389. function nsecs {
  1390. local NSECS
  1391. # test if date supports nanosecond output
  1392. if ! var_isset NSECS_DISABLED; then
  1393. NSECS=$(date_fix %N 2> /dev/null | head -1 |grep -e "^[[:digit:]]\{9\}$")
  1394. [ -n "$NSECS" ] && NSECS_DISABLED=0 || NSECS_DISABLED=1
  1395. fi
  1396.  
  1397. # add 9 digits, not all date(s) deliver nsecs eg. busybox date
  1398. if [ "$NSECS_DISABLED" == "1" ]; then
  1399. date_fix %s000000000
  1400. else
  1401. date_fix %s%N
  1402. fi
  1403. }
  1404.  
  1405. function nsecs_to_sec {
  1406. echo $(($1/1000000000)).$(printf "%03d" $(($1/1000000%1000)) )
  1407. }
  1408.  
  1409. function datefull_from_nsecs {
  1410. date_from_nsecs $1 '%F %T'
  1411. }
  1412.  
  1413. function date_from_nsecs {
  1414. local FORMAT=${2:-%T}
  1415. local TIME=$(nsecs_to_sec $1)
  1416. local SECS=${TIME%.*}
  1417. local DATE=$(date_fix "%T" ${SECS:-0})
  1418. echo $DATE.${TIME#*.}
  1419. }
  1420.  
  1421. function var_isset {
  1422. if [ -z "$1" ]; then
  1423. echo "ERROR: function var_isset needs a string as parameter"
  1424. elif eval "[ \"\${$1}\" == 'not_set' ]" || eval "[ \"\${$1-not_set}\" != 'not_set' ]"; then
  1425. return 0
  1426. fi
  1427. return 1
  1428. }
  1429.  
  1430. function is_condition {
  1431. local CMD=$(tolower "$1")
  1432. [ "$CMD" == 'and' ] || [ "$CMD" == 'or' ]
  1433. }
  1434.  
  1435. function is_groupMarker {
  1436. local CMD=$(tolower "$1")
  1437. [ "$CMD" == 'groupin' ] || [ "$CMD" == 'groupout' ]
  1438. }
  1439.  
  1440. function is_command {
  1441. local CMD=$(tolower "$1")
  1442. ! is_condition "$CMD" && ! is_groupMarker "$CMD"
  1443. }
  1444.  
  1445. function url_encode {
  1446. # utilize python, silently do nothing on error - because no python no duplicity
  1447. OUT=$("$(python_binary)" -c "
  1448. try: import urllib.request as urllib
  1449. except ImportError: import urllib
  1450. print(urllib.${2}quote('$1'));
  1451. " 2>/dev/null ); ERR=$?
  1452. [ "$ERR" -eq 0 ] && echo $OUT || echo $1
  1453. }
  1454.  
  1455. function url_decode {
  1456. # reuse function above with a simple string param hack
  1457. url_encode "$1" "un"
  1458. }
  1459.  
  1460. function toupper {
  1461. echo "$@"|awk '$0=toupper($0)'
  1462. }
  1463.  
  1464. function tolower {
  1465. echo "$@"|awk '$0=tolower($0)'
  1466. }
  1467.  
  1468. function isnumber {
  1469. case "$*" in
  1470. ''|*[!0-9]*) return 1;;
  1471. *) return 0;;
  1472. esac
  1473. }
  1474.  
  1475. #function tmp_space {
  1476. #
  1477. # if ! isnumber $VOLSIZE; then
  1478. # inform "failed to determine free space (please report, this is a bug)"
  1479. # return
  1480. # fi
  1481. #
  1482. # get free temp space
  1483. # TEMP_FREE="$(df -P -k "$TEMP_DIR" 2>/dev/null | awk 'END{pos=(NF-2);if(pos>0) print $pos;}')"
  1484. # # check for free space or FAIL
  1485. # if [ $((${TEMP_FREE:-0}-${VOLSIZE:-0}*1024)) -lt 0-lt 0 ]; then
  1486. # error "Temporary file space '$TEMP_DIR' free space is smaller ($((TEMP_FREE/1024))MB)
  1487. #than one duplicity volume (${VOLSIZE}MB).
  1488. #
  1489. # Hint: Free space or change TEMP_DIR setting."
  1490. #fi
  1491. #
  1492. #}
  1493.  
  1494. function gpg_disabled {
  1495. echo "${GPG_KEY}" | grep -iq -e '^disabled$'
  1496. }
  1497.  
  1498. # usage: join SEPARATOR "entry1" "entry2"
  1499. function join {
  1500. local SEP="$1" ENTRY OUT; shift;
  1501. for ENTRY in "$@"; do
  1502. ENTRY=${ENTRY//$SEP/\\$SEP}
  1503. [ -z "$OUT" ] && OUT=$ENTRY || OUT="$OUT$SEP$ENTRY"
  1504. done
  1505. echo $OUT
  1506. }
  1507.  
  1508. function gpg_signing {
  1509. echo ${GPG_KEY_SIGN} | grep -v -q -e '^disabled$'
  1510. }
  1511.  
  1512. # parameter key id, key_type
  1513. function gpg_keyfile {
  1514. local GPG_KEY=$(gpg_key_legalize $1) TYPE="$2"
  1515. local KEYFILE="${KEYFILE//.asc/${GPG_KEY:+.$GPG_KEY}.asc}"
  1516. echo "${KEYFILE//.asc/${TYPE:+.$(tolower $TYPE)}.asc}"
  1517. }
  1518.  
  1519. # parameter key id
  1520. function gpg_import {
  1521. local i FILE FOUND=0 KEY_ID="$1" KEY_TYPE="$2" KEY_FP="" ERR=0
  1522. # create a list of legacy key file names and current naming scheme
  1523. # we always import pub and sec if they are avail in conf folder
  1524. local KEYFILES=( "$CONFDIR/gpgkey" $(gpg_keyfile "$KEY_ID") \
  1525. $(gpg_keyfile "$KEY_ID" PUB) $(gpg_keyfile "$KEY_ID" SEC))
  1526.  
  1527. # Try autoimport from existing old gpgkey files
  1528. # and new gpgkey.XXX.asc files (since v1.4.2)
  1529. # and even newer gpgkey.XXX.[pub|sec].asc
  1530. for (( i = 0 ; i < ${#KEYFILES[@]} ; i++ )); do
  1531. FILE=${KEYFILES[$i]}
  1532. if [ -f "$FILE" ]; then
  1533. FOUND=1
  1534.  
  1535. CMD_MSG="Import keyfile '$FILE' to keyring"
  1536. run_cmd gpg $GPG_OPTS --batch --import $(qw "$FILE")
  1537. if [ "$?" != "0" ]; then
  1538. warning "Import failed.${CMD_OUT:+\n$CMD_OUT}"
  1539. ERR=1
  1540. # continue with next
  1541. continue
  1542. fi
  1543. fi
  1544. done
  1545.  
  1546. if [ "$FOUND" -eq 0 ]; then
  1547. warning "No keyfile for '$KEY_ID' found in profile\n'$CONFDIR'."
  1548. fi
  1549.  
  1550. # try to set trust automagically
  1551. CMD_MSG="Autoset trust of key '$KEY_ID' to ultimate"
  1552. run_cmd echo $(gpg_fingerprint "$KEY_ID"):6: \| gpg $GPG_OPTS --import-ownertrust --batch --logger-fd 1
  1553. if [ "$?" = "0" ] && [ -z "$PREVIEW" ]; then
  1554. # success on all levels, we're done
  1555. return $ERR
  1556. fi
  1557.  
  1558. # failover: user has to set trust manually
  1559. echo -e "For $ME_NAME to work you have to set the trust level
  1560. with the command \"trust\" to \"ultimate\" (5) now.
  1561. Exit the edit mode of gpg with \"quit\"."
  1562. CMD_MSG="Running gpg to manually edit key '$KEY_ID'"
  1563. run_cmd sleep 5\; gpg $GPG_OPTS --edit-key $(qw "$KEY_ID")
  1564.  
  1565. return $ERR
  1566. }
  1567.  
  1568. # see 'How to specify a user ID' on gpg manpage
  1569. function gpg_fingerprint {
  1570. local PRINT=$(gpg $GPG_OPTS --fingerprint "$1" 2>&1|awk -F= 'NR==2{gsub(/ /,"",$2);$2=toupper($2); if ( $2 ~ /^[A-F0-9]+$/ && length($2) == 40 ) print $2; else exit 1}') \
  1571. && [ -n "$PRINT" ] && echo $PRINT && return 0
  1572. return 1
  1573. }
  1574.  
  1575. function gpg_export_if_needed {
  1576. local SUCCESS FILE KEY_TYPE
  1577. local TMPFILE="$TEMP_DIR/${ME_NAME}.$$.$(date_fix %s).gpgexp"
  1578. for KEY_ID in "$@"; do
  1579. # check if already exported, do it if not
  1580. for KEY_TYPE in PUB SEC; do
  1581. FILE="$(gpg_keyfile "$KEY_ID" $KEY_TYPE)"
  1582. if [ ! -f "$FILE" ] && eval gpg_$(tolower $KEY_TYPE)_avail \"$KEY_ID\"; then
  1583. # exporting
  1584. CMD_MSG="Backup $KEY_TYPE key '$KEY_ID' to profile."
  1585. # gpg2.1 insists on passphrase here, gpg2.0- happily exports w/o it
  1586. # we pipe an empty string when GPG_PW is not set to avoid gpg silently waiting for input
  1587. run_cmd $(gpg_pass_pipein GPG_PW_SIGN GPG_PW) gpg $GPG_OPTS $GPG_USEAGENT $(gpg_param_passwd GPG_PW_SIGN GPG_PW) --armor --export"$(test "SEC" = "$KEY_TYPE" && echo -secret-keys)" $(qw "$KEY_ID") '>>' $(qw "$TMPFILE")
  1588. CMD_ERR=$?
  1589.  
  1590. if [ "$CMD_ERR" = "0" ]; then
  1591. CMD_MSG="Write file '"$(basename "$FILE")"'"
  1592. run_cmd mv $(qw "$TMPFILE") $(qw "$FILE")
  1593. fi
  1594.  
  1595. if [ "$CMD_ERR" != "0" ]; then
  1596. warning "Backup failed.${CMD_OUT:+\n$CMD_OUT}"
  1597. else
  1598. SUCCESS=1
  1599. fi
  1600.  
  1601. # cleanup
  1602. rm $(qw "$TMPFILE") 1>/dev/null 2>&1
  1603. fi
  1604. done
  1605. done
  1606.  
  1607. [ -n "$SUCCESS" ] && inform "$ME_NAME exported new keys to your profile.
  1608. You should backup your changed profile folder now and store it in a safe place."
  1609. }
  1610.  
  1611. # replace all non-alnum chars with underscore (for file operations)
  1612. function gpg_key_legalize {
  1613. echo $* | awk '{gsub(/[^a-zA-Z0-9]/,"_",$0); print}'
  1614. }
  1615.  
  1616. function gpg_key_cache {
  1617. local RES
  1618. local MODE=$1
  1619. shift
  1620. local PREFIX="GPG_KEY"
  1621. local SUFFIX=$(gpg_key_legalize "$@")
  1622. local KEYID="$*"
  1623. local CACHE="${PREFIX}_${MODE}_${SUFFIX}"
  1624. if [ "$MODE" = "RESET" ]; then
  1625. eval unset ${PREFIX}_PUB_$SUFFIX ${PREFIX}_SEC_$SUFFIX
  1626. return 255
  1627. elif ! var_isset "$CACHE"; then
  1628. if [ "$MODE" = "PUB" ]; then
  1629. RES=$(gpg $GPG_OPTS --list-key "$KEYID" > /dev/null 2>&1; echo -n $?)
  1630. elif [ "$MODE" = "SEC" ]; then
  1631. RES=$(gpg $GPG_OPTS --list-secret-key "$KEYID" > /dev/null 2>&1; echo -n $?)
  1632. else
  1633. return 255
  1634. fi
  1635. eval $CACHE=$RES
  1636. fi
  1637. eval return \$$CACHE
  1638. }
  1639.  
  1640. function gpg_pub_avail {
  1641. gpg_key_cache PUB "$@"
  1642. }
  1643.  
  1644. function gpg_sec_avail {
  1645. gpg_key_cache SEC "$@"
  1646. }
  1647.  
  1648. function gpg_key_format {
  1649. echo $1 | grep -q '^[0-9a-fA-F]\{8\}$'
  1650. }
  1651.  
  1652. # splits a comma separated line into lines, respects escaped commas
  1653. function gpg_split_keyset {
  1654. local LIST
  1655. LIST=$(echo "$@" | awk '{ gsub(/,/,"\n",$0); gsub(/\\\n/,",",$0); print $0 }')
  1656. echo -e "$LIST"
  1657. }
  1658.  
  1659. function gpg_prefix_keyset {
  1660. local PREFIX="$1" OUT=""
  1661. shift
  1662. for KEY_ID in "$@"; do
  1663. OUT="${OUT} $PREFIX $(qw ${KEY_ID})"
  1664. done
  1665. echo $OUT
  1666. }
  1667.  
  1668. # grep a variable from conf text file (currently not used)
  1669. function gpg_passwd {
  1670. [ -r "$CONF" ] && \
  1671. awk '/^[ \t]*GPG_PW[ \t=]/{\
  1672. sub(/^[ \t]*GPG_PW[ \t]*=*/,"",$0);\
  1673. gsub(/^[ \t]*[\047"]|[\047"][ \t]*$/,"",$0);\
  1674. print $0; exit}' "$CONF"
  1675. }
  1676.  
  1677. # return success if at least one secret key is available
  1678. function gpg_key_decryptable {
  1679. local KEY_ID
  1680. for KEY_ID in "${GPG_KEYS_ENC_ARRAY[@]}"; do
  1681. gpg_sec_avail "$KEY_ID" && return 0
  1682. done
  1683. return 1
  1684. }
  1685.  
  1686. function gpg_symmetric {
  1687. [ -z "${GPG_KEY}${GPG_KEYS_ENC_ARRAY}" ]
  1688. }
  1689.  
  1690. # checks for max two params if they are set, typically GPG_PW & GPG_PW_SIGN
  1691. function gpg_param_passwd {
  1692. var_isset GPG_USEAGENT && exit 1
  1693.  
  1694. if ( [ -n "$1" ] && var_isset "$1" ) || ( [ -n "$2" ] && var_isset "$2" ); then
  1695. echo "--passphrase-fd 0 --batch"
  1696. fi
  1697. }
  1698.  
  1699. # select the earlist defined and create an "echo <value> |" string
  1700. function gpg_pass_pipein {
  1701. var_isset GPG_USEAGENT && exit 1
  1702.  
  1703. for var in "$@"
  1704. do
  1705. if var_isset "$var"; then
  1706. echo "echo $(qw $(eval echo \$$var)) |"
  1707. return 0
  1708. fi
  1709. done
  1710.  
  1711. return 1
  1712. }
  1713.  
  1714. # checks if gpg-agent is available, returns error code
  1715. # 0 on success
  1716. # 1 if GPG_AGENT_INFO is not set (unused, should probably be merged w/ 3)
  1717. # 2 if GPG_AGENT_INFO is stale
  1718. # 3 cannot connect to gpg-agent
  1719. function gpg_agent_avail {
  1720. # GPG_AGENT_INFO is deprecated in gpg2.1,
  1721. # first try to connect to a possibly running agent here
  1722. local ERR=3
  1723. gpg-agent > /dev/null 2>&1 && return 0
  1724.  
  1725. # detect stale pid in legacy GPG_AGENT_INFO env var
  1726. if var_isset GPG_AGENT_INFO; then
  1727. # check if a pid matching process is running at all
  1728. local GPG_AGENT_PID=$(echo $GPG_AGENT_INFO|awk -F: '{print $2}')
  1729. if isnumber "$GPG_AGENT_PID"; then
  1730. ps -p "$GPG_AGENT_PID" > /dev/null 2>&1 || ERR=2
  1731. fi
  1732. fi
  1733.  
  1734. return $ERR
  1735. }
  1736.  
  1737. function gpg_custom_binary {
  1738. var_isset GPG && [ "$GPG" != "$DEFAULT_GPG" ] &&\
  1739. echo "--gpg-binary $(qw "$GPG")"
  1740. }
  1741.  
  1742. function gpg_binary {
  1743. local BIN
  1744. var_isset GPG && BIN="$GPG" || BIN="$DEFAULT_GPG"
  1745. echo "$BIN"
  1746. }
  1747.  
  1748. function gpg_avail {
  1749. lookup "$(gpg_binary)"
  1750. }
  1751.  
  1752. # enforce the use of our selected gpg binary
  1753. function gpg {
  1754. command "$(gpg_binary)" "$@"
  1755. }
  1756. export -f gpg
  1757.  
  1758. # start of script #######################################################################
  1759.  
  1760. # confidentiality first, all we create is only readable by us
  1761. umask 077
  1762.  
  1763. # check if ftplicity is there & executable
  1764. [ -n "$ME_LONG" ] && [ -x "$ME_LONG" ] || error "$ME missing. Executable & available in path? ($ME_LONG)"
  1765.  
  1766. if [ ${#@} -eq 1 ]; then
  1767. cmd="${1}"
  1768. else
  1769. FTPLCFG="${1}" ; cmd="${2}"
  1770. fi
  1771.  
  1772. # deal with command before profile validation calls
  1773. # show requested version
  1774. # OR requested usage info
  1775. # OR create a profile
  1776. # OR fall through
  1777. ##if [ ${#@} -le 2 ]; then
  1778. case "$cmd" in
  1779. changelog)
  1780. changelog
  1781. exit 0
  1782. ;;
  1783. create)
  1784. set_config
  1785. if [ -d "$CONFDIR" ]; then
  1786. error "The profile '$FTPLCFG' already exists in
  1787. '$CONFDIR'.
  1788.  
  1789. Hint:
  1790. If you _really_ want to create a new profile by this name you will
  1791. have to manually delete the existing profile folder first."
  1792. exit 1
  1793. else
  1794. create_config
  1795. exit 0
  1796. fi
  1797. ;;
  1798. txt2man)
  1799. set_config
  1800. usage_txt2man
  1801. exit 0
  1802. ;;
  1803. usage|-help|--help|-h|-H)
  1804. set_config
  1805. usage_info
  1806. exit 0
  1807. ;;
  1808. version|-version|--version|-v|-V)
  1809. # profile can override GPG/PYTHON, so import it if it was given
  1810. var_isset FTPLCFG && {
  1811. set_config
  1812. [ -r "$CONF" ] && . "$CONF" || warning "Cannot import config '$CONF'."
  1813. }
  1814. version_info_using
  1815. exit 0
  1816. ;;
  1817. # fallthrough.. we got a command that needs an existing profile
  1818. *)
  1819. # if we reach here, user either forgot profile or chose wrong profileless command
  1820. if [ ${#@} -le 1 ]; then
  1821. error "\
  1822. Missing or wrong parameters.
  1823. Only the commands
  1824. changelog, create, usage, txt2man, version
  1825. can be called without selecting an existing profile first.
  1826. Your command was '$cmd'.
  1827.  
  1828. Hint: Run '$ME usage' to get help."
  1829. fi
  1830. esac
  1831.  
  1832.  
  1833. # Hello world
  1834. echo "Start $ME v$ME_VERSION, time is $(date_fix '%F %T')."
  1835.  
  1836. # check system environment
  1837.  
  1838. # is duplicity avail
  1839. lookup duplicity || error_path "duplicity missing. installed und available in path?"
  1840. # init, exec duplicity version check info
  1841. duplicity_python_binary_parse
  1842. duplicity_version_get
  1843.  
  1844. # check for certain important helper programs
  1845. for f in awk grep "$(python_binary)"; do
  1846. lookup "$f" || \
  1847. error_path "$f missing. installed und available in path?"
  1848. done
  1849.  
  1850. ### read configuration
  1851. set_config
  1852. # check validity
  1853. if [ ! -d "$CONFDIR" ]; then
  1854. error "Selected profile '$FTPLCFG' does not resolve to a profile folder in
  1855. '$CONFDIR'.
  1856.  
  1857. Hints:
  1858. Select one of the available profiles: $(for d in "$(dirname "$CONFDIR")"/*/; do [ -e "$d" ] || [ -L "$d" ] || continue; printf "$sep'$(basename "$d")'"; sep=",";done)
  1859. Use '$ME <name> create' to create a new profile.
  1860. Use '$ME usage' to get usage help."
  1861. elif [ ! -x "$CONFDIR" ]; then
  1862. error "\
  1863. Profile folder in '$CONFDIR' cannot be accessed.
  1864.  
  1865. Hint:
  1866. Check the filesystem permissions and set directory accessible e.g. 'chmod 700'."
  1867. elif [ ! -f "$CONF" ] ; then
  1868. error "'$CONF' not found."
  1869. elif [ ! -r "$CONF" ] ; then
  1870. error "'$CONF' not readable."
  1871. else
  1872. . "$CONF"
  1873. #KEYFILE="${KEYFILE//.asc/${GPG_KEY:+.$GPG_KEY}.asc}"
  1874. TEMP_DIR=${TEMP_DIR:-'/tmp'}
  1875. # backward compatibility: old TARGET_PW overrides silently new TARGET_PASS if set
  1876. if var_isset 'TARGET_PW'; then
  1877. TARGET_PASS="${TARGET_PW}"
  1878. fi
  1879. fi
  1880. echo "Using profile '$CONFDIR'."
  1881.  
  1882. # secure config dir, if needed w/ warning
  1883. secureconf
  1884.  
  1885. # split TARGET in handy variables
  1886. TARGET_SPLIT_URL=$(echo "$TARGET" | awk '{ \
  1887. target=$0; match(target,/^([^\/:]+):\/\//); \
  1888. prot=substr(target,RSTART,RLENGTH);\
  1889. rest=substr(target,RSTART+RLENGTH); \
  1890. if (credsavail=match(rest,/^[^@]*@/)){\
  1891. creds=substr(rest,RSTART,RLENGTH-1);\
  1892. credcount=split(creds,cred,":");\
  1893. rest=substr(rest,RLENGTH+1);\
  1894. # split creds with regexp\
  1895. match(creds,/^([^:]+)/);\
  1896. user=substr(creds,RSTART,RLENGTH);\
  1897. pass=substr(creds,RSTART+1+RLENGTH);\
  1898. };\
  1899. # filter quotes or escape them\
  1900. gsub(/[\047\042]/,"",prot);\
  1901. gsub(/[\047\042]/,"",rest);\
  1902. gsub(/[\047]/,"\047\\\047\047",creds);\
  1903. print "TARGET_URL_PROT=\047"prot"\047\n"\
  1904. "TARGET_URL_HOSTPATH=\047"rest"\047\n"\
  1905. "TARGET_URL_CREDS=\047"creds"\047\n";\
  1906. if(user){\
  1907. gsub(/[\047]/,"\047\\\047\047",user);\
  1908. print "TARGET_URL_USER=\047"user"\047\n"}\
  1909. if(pass){\
  1910. gsub(/[\047]/,"\047\\\047\047",pass);\
  1911. print "TARGET_URL_PASS=$(url_decode \047"pass"\047)\n"}\
  1912. }')
  1913. eval "${TARGET_SPLIT_URL}"
  1914.  
  1915. # fetch commmand from parameters ########################################################
  1916. # Hint: cmds is also used to check if authentification info sufficient in the next step
  1917. cmds="$2"; shift 2
  1918.  
  1919. # complain if command(s) missing
  1920. [ -z $cmds ] && error " No command given.
  1921.  
  1922. Hint:
  1923. Use '$ME usage' to get usage help."
  1924.  
  1925. # process params
  1926. for param in "$@"; do
  1927. #echo !$param!
  1928. case "$param" in
  1929. # enable ftplicity preview mode
  1930. '--preview')
  1931. PREVIEW=1
  1932.  ;;
  1933. # interpret duplicity disable encr switch
  1934. '--disable-encryption')
  1935. GPG_KEY='disabled'
  1936.  ;;
  1937. *)
  1938. if [ `echo "$param" | grep -e "^-"` ] || \
  1939. [ `echo "$last_param" | grep -e "^-"` ] ; then
  1940. # forward parameter[/option pairs] to duplicity
  1941. dupl_opts["${#dupl_opts[@]}"]=${param}
  1942. else
  1943. # anything else must be a parameter (eg. for fetch, ...)
  1944. ftpl_pars["${#ftpl_pars[@]}"]=${param}
  1945. fi
  1946. last_param=${param}
  1947.  ;;
  1948. esac
  1949. done
  1950.  
  1951. # plausibility check config - VARS & KEY ################################################
  1952. # check if src, trg, trg pw
  1953. # auth info sufficient
  1954. # gpg key, gpg pwd (might be empty) set in config
  1955. # OR key in local gpg db
  1956. # OR key can be imported from keyfile
  1957. # OR fail
  1958. if [ -z "$SOURCE" ] || [ "$SOURCE" == "${DEFAULT_SOURCE}" ]; then
  1959. error " Source Path (setting SOURCE) not set or still default value in conf file
  1960. '$CONF'."
  1961.  
  1962. elif [ -z "$TARGET" ] || [ "$TARGET" == "${DEFAULT_TARGET}" ]; then
  1963. error " Backup Target (setting TARGET) not set or still default value in conf file
  1964. '$CONF'."
  1965.  
  1966. elif var_isset 'TARGET_USER' && var_isset 'TARGET_URL_USER' && \
  1967. [ "${TARGET_USER}" != "${TARGET_URL_USER}" ]; then
  1968. error " TARGET_USER ('${TARGET_USER}') _and_ user in TARGET url ('${TARGET_URL_USER}')
  1969. are configured with different values. There can be only one.
  1970.  
  1971. Hint: Remove conflicting setting."
  1972.  
  1973. elif var_isset 'TARGET_PASS' && var_isset 'TARGET_URL_PASS' && \
  1974. [ "${TARGET_PASS}" != "${TARGET_URL_PASS}" ]; then
  1975. error " TARGET_PASS ('${TARGET_PASS}') _and_ password in TARGET url ('${TARGET_URL_PASS}')
  1976. are configured with different values. There can be only one.
  1977.  
  1978. Hint: Remove conflicting setting."
  1979. fi
  1980.  
  1981. # GPG config plausibility check1 (disabled check) #############################
  1982. if gpg_disabled; then
  1983.  : # encryption disabled, all is well
  1984. elif [ -z "${GPG_KEY}${GPG_KEYS_ENC}${GPG_KEY_SIGN}" ] && ! var_isset 'GPG_PW'; then
  1985. warning "GPG_KEY, GPG_KEYS_ENC, GPG_KEY_SIGN and GPG_PW are empty/not set in conf file
  1986. '$CONF'.
  1987. Will disable encryption for duplicity now.
  1988.  
  1989. Hint:
  1990. If you really want to use _no_ encryption you can disable this warning by
  1991. setting GPG_KEY='disabled' in conf file."
  1992. GPG_KEY='disabled'
  1993. fi
  1994.  
  1995. # GPG availability check (now we know if gpg is really needed)#################
  1996. if ! gpg_disabled; then
  1997. gpg_avail || error_path "gpg '$(gpg_binary)' missing. installed und available in path?"
  1998. fi
  1999.  
  2000. # Output versions info ########################################################
  2001. using_info
  2002.  
  2003. # GPG create key settings, config check2 (needs gpg) ##########################
  2004. if gpg_disabled; then
  2005.  : # the following tests are not necessary
  2006. else
  2007.  
  2008. # we test this early as any invocation gpg2.1+ starts gpg-agent automatically
  2009. GPG_AGENT_ERR=$(gpg_agent_avail ; echo $?)
  2010.  
  2011. # enc key still default?
  2012. if [ "$GPG_KEY" == "${DEFAULT_GPG_KEY}" ]; then
  2013. error_gpg "Encryption Key GPG_KEY still default in conf file
  2014. '$CONF'."
  2015. fi
  2016.  
  2017. # create array of gpg encr keys, for further processing
  2018. OIFS="$IFS" IFS=$'\n'
  2019. GPG_KEYS_ENC_ARRAY=( $( gpg_split_keyset ${GPG_KEY},${GPG_KEYS_ENC} ) )
  2020. IFS="$OIFS"
  2021.  
  2022. # pw set?
  2023. # symmetric needs one, always
  2024. if gpg_symmetric && ( [ -z "$GPG_PW" ] || [ "$GPG_PW" == "${DEFAULT_GPG_PW}" ] ) \
  2025.  ; then
  2026. error_gpg "Encryption passphrase GPG_PW (needed for symmetric encryption)
  2027. is empty/not set or still default value in conf file
  2028. '$CONF'."
  2029. fi
  2030. # this is a technicality, we can only pump one pass via pipe into gpg
  2031. # but symmetric already always needs one for encryption
  2032. if gpg_symmetric && var_isset GPG_PW && var_isset GPG_PW_SIGN &&\
  2033. [ -n "$GPG_PW_SIGN" ] && [ "$GPG_PW" != "$GPG_PW_SIGN" ]; then
  2034. error_gpg "GPG_PW _and_ GPG_PW_SIGN are defined but not identical in config
  2035. '$CONF'.
  2036. This is unfortunately impossible. For details see duplicity manpage,
  2037. section 'A Note On Symmetric Encryption And Signing'.
  2038.  
  2039. Tip: Separate signing keys may have empty passwords e.g. GPG_PW_SIGN=''.
  2040. Tip2: Use gpg-agent."
  2041. fi
  2042.  
  2043. # check gpg encr public keys availability
  2044. for (( i = 0 ; i < ${#GPG_KEYS_ENC_ARRAY[@]} ; i++ )); do
  2045. KEY_ID="${GPG_KEYS_ENC_ARRAY[$i]}"
  2046. # test availability, try to import, retest
  2047. if ! gpg_pub_avail "${KEY_ID}"; then
  2048. echo "Encryption public key '${KEY_ID}' not found."
  2049. gpg_import "${KEY_ID}" PUB
  2050. gpg_key_cache RESET "${KEY_ID}"
  2051. gpg_pub_avail "${KEY_ID}" || error_gpg_key "${KEY_ID}" "Public"
  2052. fi
  2053. done
  2054.  
  2055. # gpg secret sign key availability
  2056. # if none set, autoset first encryption key as sign key
  2057. if ! gpg_signing; then
  2058. echo "Signing disabled per configuration."
  2059. # try first key, if one set
  2060. elif ! var_isset 'GPG_KEY_SIGN'; then
  2061. KEY_ID="${GPG_KEYS_ENC_ARRAY[0]}"
  2062. if [ -z "${KEY_ID}" ]; then
  2063. echo "Signing disabled. No GPG_KEY entries in config."
  2064. GPG_KEY_SIGN='disabled'
  2065. else
  2066. # use avail OR try import OR fail
  2067. if gpg_sec_avail "${KEY_ID}"; then
  2068. GPG_KEY_SIGN="${KEY_ID}"
  2069. else
  2070. gpg_import "${KEY_ID}" SEC
  2071. gpg_key_cache RESET "${KEY_ID}"
  2072. if gpg_sec_avail "${KEY_ID}"; then
  2073. GPG_KEY_SIGN="${KEY_ID}"
  2074. fi
  2075. fi
  2076.  
  2077. # interpret sign key setting
  2078. if var_isset 'GPG_KEY_SIGN'; then
  2079. echo "Autoset found secret key of first GPG_KEY entry '${KEY_ID}' for signing."
  2080. else
  2081. echo "Signing disabled. First GPG_KEY entry's '${KEY_ID}' private key is missing."
  2082. GPG_KEY_SIGN='disabled'
  2083. fi
  2084. fi
  2085. else
  2086. KEY_ID="${GPG_KEY_SIGN}"
  2087. if ! gpg_sec_avail "${KEY_ID}"; then
  2088. inform "Secret signing key defined in setting GPG_KEY_SIGN='${KEY_ID}' not found.\nTry to import."
  2089. gpg_import "${KEY_ID}" SEC
  2090. gpg_key_cache RESET "${KEY_ID}"
  2091. gpg_sec_avail "${KEY_ID}" || error_gpg_key "${KEY_ID}" "Private"
  2092. fi
  2093. fi
  2094.  
  2095. # using GPG_AGENT_ERR set early above, try to autoenable gpg-agent or issue some warnings
  2096. # key enc can deal without, but might profit from gpg-agent
  2097. # if GPG_PW is not set alltogether
  2098. # if signing key is different from first (main) enc key (we can only pipe one pass into gpg)
  2099. if ! gpg_symmetric && \
  2100. ( ! var_isset GPG_PW || \
  2101. ( gpg_signing && ! var_isset GPG_PW_SIGN && [ "$GPG_KEY_SIGN" != "${GPG_KEYS_ENC_ARRAY[0]}" ] ) ); then
  2102.  
  2103. if [ "$GPG_AGENT_ERR" -eq 1 ]; then
  2104. warning "Cannot use gpg-agent. GPG_AGENT_INFO not set."
  2105. elif [ "$GPG_AGENT_ERR" -eq 2 ]; then
  2106. warning "Cannot use gpg-agent! GPG_AGENT_INFO contains stale pid."
  2107. elif [ "$GPG_AGENT_ERR" -eq 3 ]; then
  2108. warning "No running gpg-agent found although GPG_PW or GPG_PW_SIGN (enc != sign key) not set."
  2109. else
  2110. echo "Enable gpg-agent usage. Running gpg-agent instance found and GPG_PW or GPG_PW_SIGN (enc != sign key) not set."
  2111. GPG_USEAGENT="--use-agent"
  2112. fi
  2113. fi
  2114.  
  2115. # end GPG config plausibility check2
  2116. fi
  2117.  
  2118. # config plausibility check - SPACE ###########################################
  2119.  
  2120. # is tmp is a folder and writable
  2121. CMD_MSG="Checking TEMP_DIR '${TEMP_DIR}' is a folder and writable"
  2122. run_cmd test -d $(qw "$TEMP_DIR") '&&' test -w $(qw "$TEMP_DIR")
  2123. if [ "$?" != "0" ]; then
  2124. error "Temporary file space '$TEMP_DIR' is not a directory or writable."
  2125. fi
  2126.  
  2127.  
  2128. # get volsize, default duplicity volume size is 25MB since v0.5.07
  2129. VOLSIZE=${VOLSIZE:-25}
  2130. # double if asynch is on
  2131. echo $@ $DUPL_PARAMS | grep -q -e '--asynchronous-upload' && FACTOR=2 || FACTOR=1
  2132.  
  2133. # TODO: check for enough (async= upload space and WARN only
  2134. # use function tmp_space
  2135. #echo TODO: reimplent tmp space check
  2136.  
  2137.  
  2138. # test - GPG SANITY #####################################################################
  2139. # if encryption is disabled, skip this whole section
  2140. if gpg_disabled; then
  2141. echo -e "Test - En/Decryption skipped. (GPG disabled)"
  2142. elif [ "$GPG_TEST" = "disabled" ]; then
  2143. echo -e "Test - En/Decryption skipped. (Testing disabled)"
  2144. else
  2145.  
  2146. GPG_TEST="$TEMP_DIR/${ME_NAME}.$$.$(date_fix %s)"
  2147. function cleanup_gpgtest {
  2148. echo -en "Cleanup - Delete '${GPG_TEST}_*'"
  2149. rm "${GPG_TEST}"_* 2>/dev/null && echo "(OK)" || echo "(FAILED)"
  2150. }
  2151.  
  2152. # signing enabled?
  2153. if gpg_signing; then
  2154. CMD_PARAM_SIGN="--sign --default-key $(qw ${GPG_KEY_SIGN})"
  2155. CMD_MSG_SIGN="Sign with '${GPG_KEY_SIGN}'"
  2156. fi
  2157.  
  2158. # using keys
  2159. if [ ${#GPG_KEYS_ENC_ARRAY[@]} -gt 0 ]; then
  2160.  
  2161. for KEY_ID in "${GPG_KEYS_ENC_ARRAY[@]}"; do
  2162. CMD_PARAMS="$CMD_PARAMS -r $(qw ${KEY_ID})"
  2163. done
  2164. # check encrypting
  2165. CMD_MSG="Test - Encrypt to '$(join "','" "${GPG_KEYS_ENC_ARRAY[@]}")'${CMD_MSG_SIGN:+ & $CMD_MSG_SIGN}"
  2166. run_cmd $(gpg_pass_pipein GPG_PW_SIGN GPG_PW) gpg $CMD_PARAM_SIGN $(gpg_param_passwd GPG_PW_SIGN GPG_PW) $CMD_PARAMS $GPG_USEAGENT --status-fd 1 $GPG_OPTS -o $(qw "${GPG_TEST}_ENC") -e $(qw "$ME_LONG")
  2167. CMD_ERR=$?
  2168.  
  2169. if [ "$CMD_ERR" != "0" ]; then
  2170. KEY_NOTRUST=$(echo "$CMD_OUT"|awk '/^\[GNUPG:\] INV_RECP 10/ { print $4 }')
  2171. [ -n "$KEY_NOTRUST" ] && HINT="Key '${KEY_NOTRUST}' seems to be untrusted. If you really trust this key try to
  2172. 'gpg --edit-key "$KEY_NOTRUST"' and raise the trust level to ultimate. If you
  2173. can trust all of your keys set GPG_OPTS='--trust-model always' in conf file."
  2174. error_gpg_test "Encryption failed (Code $CMD_ERR).${CMD_OUT:+\n$CMD_OUT}" "$HINT"
  2175. fi
  2176.  
  2177. # check decrypting
  2178. CMD_MSG="Test - Decrypt"
  2179. gpg_key_decryptable || CMD_DISABLED="No matching secret key available."
  2180. run_cmd $(gpg_pass_pipein GPG_PW) gpg $(gpg_param_passwd GPG_PW) $GPG_OPTS -o $(qw "${GPG_TEST}_DEC") $GPG_USEAGENT -d $(qw "${GPG_TEST}_ENC")
  2181. CMD_ERR=$?
  2182.  
  2183. if [ "$CMD_ERR" != "0" ]; then
  2184. error_gpg_test "Decryption failed.${CMD_OUT:+\n$CMD_OUT}"
  2185. fi
  2186.  
  2187. # symmetric only
  2188. else
  2189. # check encrypting
  2190. CMD_MSG="Test - Encryption with passphrase${CMD_MSG_SIGN:+ & $CMD_MSG_SIGN}"
  2191. run_cmd $(gpg_pass_pipein GPG_PW) gpg $GPG_OPTS $CMD_PARAM_SIGN --passphrase-fd 0 -o $(qw "${GPG_TEST}_ENC") --batch -c $(qw "$ME_LONG")
  2192. CMD_ERR=$?
  2193. if [ "$CMD_ERR" != "0" ]; then
  2194. error_gpg_test "Encryption failed.${CMD_OUT:+\n$CMD_OUT}"
  2195. fi
  2196.  
  2197. # check decrypting
  2198. CMD_MSG="Test - Decryption with passphrase"
  2199. run_cmd $(gpg_pass_pipein GPG_PW) gpg $GPG_OPTS --passphrase-fd 0 -o $(qw "${GPG_TEST}_DEC") --batch -d $(qw "${GPG_TEST}_ENC")
  2200. CMD_ERR=$?
  2201. if [ "$CMD_ERR" != "0" ]; then
  2202. error_gpg_test "Decryption failed.${CMD_OUT:+\n$CMD_OUT}"
  2203. fi
  2204. fi
  2205.  
  2206. # compare original w/ decryptginal
  2207. CMD_MSG="Test - Compare"
  2208. [ -r "${GPG_TEST}_DEC" ] || CMD_DISABLED="File not found. Nothing to compare."
  2209. run_cmd "test \"\$(cat '$ME_LONG')\" = \"\$(cat '${GPG_TEST}_DEC')\""
  2210. CMD_ERR=$?
  2211. if [ "$CMD_ERR" = "0" ]; then
  2212. cleanup_gpgtest
  2213. else
  2214. error_gpg_test "Comparision failed.${CMD_OUT:+\n$CMD_OUT}"
  2215. fi
  2216.  
  2217. fi # end disabled
  2218.  
  2219. ## an empty line
  2220. #echo
  2221.  
  2222. # Exclude file is needed, create it if necessary
  2223. [ -f "$EXCLUDE" ] || touch "$EXCLUDE"
  2224.  
  2225. # export only used keys, if bkp not already exists ######################################
  2226. gpg_export_if_needed "${GPG_KEYS_ENC_ARRAY[@]}" "$(gpg_signing && echo $GPG_KEY_SIGN)"
  2227.  
  2228.  
  2229. # command execution #####################################################################
  2230.  
  2231. # urldecode url vars into plain text
  2232. var_isset 'TARGET_URL_USER' && TARGET_URL_USER="$(url_decode "$TARGET_URL_USER")"
  2233. var_isset 'TARGET_URL_PASS' && TARGET_URL_PASS="$(url_decode "$TARGET_URL_PASS")"
  2234.  
  2235. # defined TARGET_USER&PASS vars replace their URL pendants
  2236. # (double defs already dealt with)
  2237. var_isset 'TARGET_USER' && TARGET_URL_USER="$TARGET_USER"
  2238. var_isset 'TARGET_PASS' && TARGET_URL_PASS="$TARGET_PASS"
  2239.  
  2240. TARGET_URL_PROT_lowercase="$(tolower "${TARGET_URL_PROT%%:*}")"
  2241.  
  2242. # issue some warnings
  2243. case "$TARGET_URL_PROT_lowercase" in
  2244. 'cf+http')
  2245. # info on missing AUTH_URL
  2246. if ! var_isset 'CLOUDFILES_AUTHURL'; then
  2247. inform "No CLOUDFILES_AUTHURL exported (in conf).
  2248. Will use default which is probably rackspace."
  2249. fi
  2250.  ;;
  2251. 'swift')
  2252. # info on possibly missing AUTH_URL
  2253. var_isset 'SWIFT_AUTHURL' ||\
  2254. warning "\
  2255. Swift will probably fail because the conf var SWIFT_AUTHURL was not exported!"
  2256.  ;;
  2257. 'rsync')
  2258. # everything in url (this backend does not support pass in env var)
  2259. # this is obsolete from version 0.6.10 (buggy), hopefully fixed in 0.6.11
  2260. # print warning older version is detected
  2261. duplicity_version_lt 610 &&
  2262. warning "\
  2263. Duplicity version '$DUPL_VERSION' does not support providing the password as
  2264. env var for rsync backend. For security reasons you should consider to
  2265. update to a version greater than '0.6.10' of duplicity."
  2266.  ;;
  2267. esac
  2268.  
  2269.  
  2270. # for all protocols we put username in url and pass into env var
  2271. # for sec�rity reasons, we url_encode username to protect special chars
  2272. # first sortout backends with special ways to handle password
  2273. case "$TARGET_URL_PROT_lowercase" in
  2274. 'imap'|'imaps')
  2275. var_isset 'TARGET_URL_PASS' && BACKEND_PARAMS="IMAP_PASSWORD=$(qw "${TARGET_URL_PASS}")"
  2276.  ;;
  2277. *)
  2278. # rest uses FTP_PASS var
  2279. var_isset 'TARGET_URL_PASS' && \
  2280. BACKEND_PARAMS="FTP_PASSWORD=$(qw "${TARGET_URL_PASS}")"
  2281.  ;;
  2282. esac
  2283. # insert url encoded username into target url if needed
  2284. if var_isset 'TARGET_URL_USER' && [ "$TARGET_URL_PROT_lowercase" != "file" ]; then
  2285. BACKEND_URL="${TARGET_URL_PROT}$(url_encode "${TARGET_URL_USER}")@${TARGET_URL_HOSTPATH}"
  2286. else
  2287. BACKEND_URL="$TARGET"
  2288. fi
  2289.  
  2290.  
  2291. # protect eval from special chars in url (e.g. open ')' in password,
  2292. # spaces in path, quotes) happens above in duplify() via quotewrap()
  2293. SOURCE="$SOURCE"
  2294. BACKEND_URL="$BACKEND_URL"
  2295. EXCLUDE="$EXCLUDE"
  2296. # since 0.7.03 --exclude-globbing-filelist is deprecated
  2297. EXCLUDE_PARAM="--exclude$(duplicity_version_lt 703 && echo -globbing)-filelist"
  2298.  
  2299. # translate backup to batch command
  2300. cmds=${cmds//backup/groupIn_pre_bkp_post_groupOut}
  2301.  
  2302. # replace magic separators to command equivalents (+=and,-=or,[=groupIn,]=groupOut)
  2303. cmds=$(awk -v cmds="$cmds" "BEGIN{ \
  2304. gsub(/\+/,\"_and_\",cmds);\
  2305. gsub(/\-/,\"_or_\",cmds);\
  2306. gsub(/\[/,\"_groupIn_\",cmds);\
  2307. gsub(/\]/,\"_groupOut_\",cmds);\
  2308. print cmds}")
  2309. # convert cmds to array, lowercase for safety
  2310. declare -a CMDS
  2311. CMDS=( $(awk "BEGIN{ cmds=tolower(\"$cmds\"); gsub(/_/,\" \",cmds); print cmds }") )
  2312.  
  2313. unset FTPL_ERR
  2314.  
  2315. # run cmds
  2316. for cmd in ${CMDS[*]};
  2317. do
  2318.  
  2319. ## init
  2320. # raise index in cmd array for pre/post param
  2321. var_isset 'CMD_NO' && CMD_NO=$((++CMD_NO)) || CMD_NO=0
  2322.  
  2323. unset CMD_VALUE CMD_NEXT CMD_PREV CND_NEXT CND_PREV
  2324.  
  2325. # get next cmd,cnd vars
  2326. nextno=$(( $CMD_NO ))
  2327. while ! var_isset 'CMD_NEXT'
  2328. do
  2329. nextno=$(($nextno+1))
  2330. if [ "$nextno" -lt "${#CMDS[@]}" ]; then
  2331. CMD_VALUE=${CMDS[$nextno]}
  2332. is_condition "$CMD_VALUE" && CND_NEXT="$CMD_VALUE" && continue
  2333. is_groupMarker "$CMD_VALUE" && continue
  2334. CMD_NEXT="$CMD_VALUE"
  2335. else
  2336. CMD_NEXT='END'
  2337. fi
  2338. done
  2339.  
  2340. # get prev cnd, cnds are skipped pseudocmds
  2341. prevno=$(( $CMD_NO ));
  2342. while ! var_isset 'CND_PREV'
  2343. do
  2344. prevno=$(($prevno-1))
  2345. if [ "$prevno" -ge 0 ]; then
  2346. CMD_VALUE=${CMDS[$prevno]}
  2347. is_condition "$CMD_VALUE" && CND_PREV="$CMD_VALUE" && break
  2348. is_command "$CMD_VALUE" && break
  2349. else
  2350. break
  2351. fi
  2352. done
  2353.  
  2354. # get prev cmd command minus skipped commands, only executed
  2355. prevno=$(( $CMD_NO - ${CMD_SKIPPED-0} ));
  2356. while ! var_isset 'CMD_PREV'
  2357. do
  2358. prevno=$(($prevno-1))
  2359. if [ "$prevno" -ge 0 ]; then
  2360. CMD_VALUE=${CMDS[$prevno]}
  2361. is_condition "$CMD_VALUE" && CND_PREV="$CMD_VALUE" && continue
  2362. is_groupMarker "$CMD_VALUE" && continue
  2363. CMD_PREV="$CMD_VALUE"
  2364. else
  2365. CMD_PREV='START'
  2366. fi
  2367. done
  2368.  
  2369. function get_cmd_skip_count {
  2370. # find closing bracket, get group skip count
  2371. local nextno=$CMD_NO
  2372. local GRP_OPEN=0
  2373. local GRP_SKIP=0
  2374. local CMD_VALUE
  2375. while [ "$nextno" -lt "${#CMDS[@]}" ]
  2376. do
  2377. nextno=$(($nextno+1))
  2378. CMD_VALUE=${CMDS[$nextno]}
  2379. GRP_SKIP=$(( ${GRP_SKIP} + 1 ));
  2380. if is_command "$CMD_VALUE" && [ "$GRP_OPEN" -lt 1 ]; then
  2381. break;
  2382. elif [ "$CMD_VALUE" == 'groupin' ]; then
  2383. GRP_OPEN=$(( ${GRP_OPEN} + 1 ))
  2384. elif [ "$CMD_VALUE" == 'groupout' ]; then
  2385. GRP_OPEN=$(( ${GRP_OPEN} - 1 ))
  2386. if [ "$GRP_OPEN" -lt 1 ]; then
  2387. break;
  2388. fi
  2389. fi
  2390. done
  2391.  
  2392. echo $GRP_SKIP;
  2393. }
  2394.  
  2395. # decision time: are we skipping already or dealing with condition "commands" or other non-cmds?
  2396. unset SKIP_NOW
  2397. if var_isset 'CMD_SKIP' && [ $CMD_SKIP -gt 0 ]; then
  2398. # skip cnd/grp cmds silently
  2399. is_command "$cmd" && echo -e "\n--- Skipping command $(toupper $cmd) ! ---"
  2400. CMD_SKIP=$(($CMD_SKIP - 1))
  2401. SKIP_NOW="yes"
  2402. elif ! var_isset 'PREVIEW' && [ "$cmd" == 'and' ] && [ "$CMD_ERR" -ne "0" ]; then
  2403. CMD_SKIP=$(get_cmd_skip_count)
  2404. # incl. this "cmd"
  2405. CMD_SKIP=$(( $CMD_SKIP + 1 ))
  2406. unset CMD_SKIPPED
  2407. SKIP_NOW="yes"
  2408. elif ! var_isset 'PREVIEW' && [ "$cmd" == 'or' ] && [ "$CMD_ERR" -eq "0" ]; then
  2409. CMD_SKIP=$(get_cmd_skip_count)
  2410. # incl. this "cmd"
  2411. CMD_SKIP=$(( $CMD_SKIP + 1 ))
  2412. unset CMD_SKIPPED
  2413. SKIP_NOW="yes"
  2414. elif is_condition "$cmd" || is_groupMarker "$cmd"; then
  2415. unset 'CMD_SKIP';
  2416. SKIP_NOW="yes"
  2417. fi
  2418.  
  2419. # let's do the skip now
  2420. if [ -n "$SKIP_NOW" ]; then
  2421. # sum up how many commands we actually skipped for the prev var routines
  2422. CMD_SKIPPED=$((${CMD_SKIPPED-0} + 1))
  2423. continue
  2424. fi
  2425.  
  2426. # save start time
  2427. RUN_START=$(nsecs)
  2428.  
  2429. # export some useful env vars for external scripts/programs to use
  2430. export PROFILE CONFDIR SOURCE TARGET_URL_PROT TARGET_URL_HOSTPATH \
  2431. TARGET_URL_USER TARGET_URL_PASS \
  2432. GPG_KEYS_ENC=$(join "\n" "${GPG_KEYS_ENC_ARRAY[@]}") GPG_KEY_SIGN \
  2433. GPG_PW CMD_PREV CMD_NEXT CMD_ERR CND_PREV CND_NEXT\
  2434. RUN_START
  2435.  
  2436. # user info
  2437. echo; separator "Start running command $(toupper $cmd) at $(date_from_nsecs $RUN_START)"
  2438.  
  2439. case "$(tolower $cmd)" in
  2440. 'pre'|'post')
  2441. if [ "$cmd" == 'pre' ]; then
  2442. script=$PRE
  2443. else
  2444. script=$POST
  2445. fi
  2446. # script execution in a subshell, protect us from failures/var overwrites
  2447. ( run_script "$script" )
  2448. ;;
  2449. 'bkp')
  2450. duplify -- "${dupl_opts[@]}" $EXCLUDE_PARAM "$EXCLUDE" \
  2451. "$SOURCE" "$BACKEND_URL"
  2452. ;;
  2453. 'incr')
  2454. duplify incr -- "${dupl_opts[@]}" $EXCLUDE_PARAM "$EXCLUDE" \
  2455. "$SOURCE" "$BACKEND_URL"
  2456. ;;
  2457. 'full')
  2458. duplify full -- "${dupl_opts[@]}" $EXCLUDE_PARAM "$EXCLUDE" \
  2459. "$SOURCE" "$BACKEND_URL"
  2460. ;;
  2461. 'verify')
  2462. TIME="${ftpl_pars[0]:+"-t ${ftpl_pars[0]}"}"
  2463. duplify verify -- $TIME "${dupl_opts[@]}" $EXCLUDE_PARAM "$EXCLUDE" \
  2464. "$BACKEND_URL" "$SOURCE"
  2465.  ;;
  2466. 'verifypath')
  2467. TIME="${ftpl_pars[2]:+"-t ${ftpl_pars[2]}"}"
  2468. IN_PATH="${ftpl_pars[0]}"; OUT_PATH="${ftpl_pars[1]}";
  2469. ( [ -z "$IN_PATH" ] || [ -z "$OUT_PATH" ] ) && error " Missing parameter <rel_bkp_path> or <local_path> for verifyPath.
  2470.  
  2471. Hint:
  2472. Syntax is -> $ME <profile> verifyPath <rel_bkp_path> <local_path> [<age>]"
  2473.  
  2474. duplify verify -- $TIME "${dupl_opts[@]}" $EXCLUDE_PARAM "$EXCLUDE" \
  2475. --file-to-restore "$IN_PATH" "$BACKEND_URL" "$OUT_PATH"
  2476. ;;
  2477. 'list')
  2478. # time param exists since 0.5.10+
  2479. TIME="${ftpl_pars[0]:+"-t ${ftpl_pars[0]}"}"
  2480. duplify list-current-files -- $TIME "${dupl_opts[@]}" "$BACKEND_URL"
  2481.  ;;
  2482. 'cleanup')
  2483. duplify cleanup -- "${dupl_opts[@]}" "$BACKEND_URL"
  2484.  ;;
  2485. 'purge')
  2486. MAX_AGE=${ftpl_pars[0]:-$MAX_AGE}
  2487. [ -z "$MAX_AGE" ] && error " Missing parameter <max_age>. Can be set in profile or as command line parameter."
  2488.  
  2489. duplify remove-older-than "${MAX_AGE}" \
  2490. -- "${dupl_opts[@]}" "$BACKEND_URL"
  2491.  ;;
  2492. 'purgefull')
  2493. MAX_FULL_BACKUPS=${ftpl_pars[0]:-$MAX_FULL_BACKUPS}
  2494. [ -z "$MAX_FULL_BACKUPS" ] && error " Missing parameter <max_full_backups>. Can be set in profile or as command line parameter."
  2495.  
  2496. duplify remove-all-but-n-full "${MAX_FULL_BACKUPS}" \
  2497. -- "${dupl_opts[@]}" "$BACKEND_URL"
  2498.  ;;
  2499. 'purgeincr')
  2500. MAX_FULLS_WITH_INCRS=${ftpl_pars[0]:-$MAX_FULLS_WITH_INCRS}
  2501. [ -z "$MAX_FULLS_WITH_INCRS" ] && error " Missing parameter <max_fulls_with_incrs>. Can be set in profile or as command line parameter."
  2502.  
  2503. duplify remove-all-inc-of-but-n-full "${MAX_FULLS_WITH_INCRS}" \
  2504. -- "${dupl_opts[@]}" "$BACKEND_URL"
  2505.  ;;
  2506. 'restore')
  2507. OUT_PATH="${ftpl_pars[0]}"; TIME="${ftpl_pars[1]:-now}";
  2508. [ -z "$OUT_PATH" ] && error " Missing parameter target_path for restore.
  2509.  
  2510. Hint:
  2511. Syntax is -> $ME <profile> restore <target_path> [<age>]"
  2512.  
  2513. duplify -- -t "$TIME" "${dupl_opts[@]}" "$BACKEND_URL" "$OUT_PATH"
  2514.  ;;
  2515. 'fetch')
  2516. IN_PATH="${ftpl_pars[0]}"; OUT_PATH="${ftpl_pars[1]}";
  2517. TIME="${ftpl_pars[2]:-now}";
  2518. ( [ -z "$IN_PATH" ] || [ -z "$OUT_PATH" ] ) && error " Missing parameter <src_path> or <target_path> for fetch.
  2519.  
  2520. Hint:
  2521. Syntax is -> $ME <profile> fetch <src_path> <target_path> [<age>]"
  2522.  
  2523. # duplicity 0.4.7 doesnt like cmd restore in combination with --file-to-restore
  2524. duplify -- --restore-time "$TIME" "${dupl_opts[@]}" \
  2525. --file-to-restore "$IN_PATH" "$BACKEND_URL" "$OUT_PATH"
  2526.  ;;
  2527. 'status')
  2528. duplify collection-status -- "${dupl_opts[@]}" "$BACKEND_URL"
  2529.  ;;
  2530. *)
  2531. error " Unknown command '$cmd'.
  2532.  
  2533. Hint:
  2534. Use '$ME usage' to get usage help."
  2535.  ;;
  2536. esac
  2537.  
  2538. CMD_ERR=$?
  2539. RUN_END=$(nsecs)
  2540. RUNTIME=$(( $RUN_END - $RUN_START ))
  2541.  
  2542. # print message on error; set error code
  2543. if [ "$CMD_ERR" -ne 0 ]; then
  2544. error_print "$(datefull_from_nsecs $RUN_END) Task '$(echo $cmd|awk '$0=toupper($0)')' failed with exit code '$CMD_ERR'."
  2545. FTPL_ERR=1
  2546. fi
  2547.  
  2548. separator "Finished state $(error_to_string $CMD_ERR) at $(date_from_nsecs $RUN_END) - \
  2549. Runtime $(printf "%02d:%02d:%02d.%03d" $((RUNTIME/1000000000/60/60)) $((RUNTIME/1000000000/60%60)) $((RUNTIME/1000000000%60)) $((RUNTIME/1000000%1000)) )"
  2550.  
  2551. done
  2552.  
  2553. exit ${FTPL_ERR}
  2554.