kind.ag 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. #include <dirent.h>
  2. #include <sys/stat.h>
  3. #include <cstring>
  4. #include <unistd.h>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <vector>
  9. #include <set>
  10. #include <algorithm>
  11. #include "stringtools.h"
  12. #include "Exception.h"
  13. #include "DateTime.h"
  14. #include "Strings.h"
  15. #include "FileName.h"
  16. #include "Image.h"
  17. #include "KindConfig.h"
  18. #include "filetools.h"
  19. #include "Lexer.h"
  20. #include "rulecomp.h"
  21. #include "kind.h"
  22. #include "expiretools.h"
  23. #include "excludetools.h"
  24. /*AppGen
  25. %% Beschreibung des Programmes:
  26. prog: archiving backup
  27. %% Beschreibung Parameter
  28. % symbolischerName, Art, Typ, Variablenname, Erklärung, Default-Wert
  29. para: vault_or_group, required, string, vault, Vault to backup
  30. %% Beschreibung der Optionen
  31. % kurz-Option, lang-Option, Typ, Variablenname, Erklärung, Default-Wert
  32. opt: c, masterconfig, string, masterConfig, Master config file, ""
  33. opt2: if not given or empty kind looks for
  34. opt2: /etc/kind/master.conf
  35. opt2: /ffp/etc/kind/master.conf
  36. opt: f, full, void, fullImage, Force full image == initial backup, false
  37. opt: B, backup, void, doBackup, Backup, false
  38. opt: E, expire, void, doExpire, Expire, false
  39. opt: C, listconfig, void, listConfig, Show configuration, false
  40. opt: I, listimages, void, listImages, List data of images, false
  41. opt2: if none of backup, expire, listconfig and listimages is specified,
  42. opt2: backup and expire is assumed.
  43. opt2: listconfig and listimages cannot be combined with other actions
  44. opt: D, dryrun, Void, dryRun, Dry run (no real backup), false
  45. opt: F, forcebackup, string, forcedBackupSet, Create image for specified backup set, ""
  46. opt: v, verbose, Void, verbose, Verbose, false
  47. opt: d, debug, Void, debug, Debug output of many data, false
  48. opt: q, quiet, Void, quiet, Be quiet - no messages, false
  49. opt: h, help, usage, ignored , This help
  50. AppGen*/
  51. using namespace std;
  52. /*AppGen:Global*/
  53. Strings banks;
  54. string findVault(const string& v);
  55. typedef pair<long int, long int> Sizes;
  56. map<string, Sizes> sizes;
  57. void readSizes(const string& logSizeFile)
  58. {
  59. if (!logSizeFile.empty() && fileExists(logSizeFile))
  60. {
  61. vector<string> ss;
  62. file2Strings(logSizeFile, ss);
  63. for (const string& s : ss)
  64. {
  65. unsigned int i = 0;
  66. string vault = getWord(s, i);
  67. long int s1 = getLongInt(s, i);
  68. long int s2 = getLongInt(s, i);
  69. try
  70. {
  71. findVault(vault);
  72. sizes[vault] = Sizes(s1, s2);
  73. }
  74. catch (...)
  75. {
  76. // ignore missing vaults
  77. }
  78. }
  79. }
  80. }
  81. void writeSizes(const string logSizeFile)
  82. {
  83. if (!logSizeFile.empty())
  84. {
  85. Strings st;
  86. for (auto s : sizes)
  87. {
  88. string h = s.first + " " + to_string(s.second.first) + " " + to_string(s.second.second);
  89. st.push_back(h);
  90. }
  91. strings2File(st, logSizeFile);
  92. }
  93. }
  94. void verbosePrint(const string& text)
  95. {
  96. if (verbose)
  97. cout << " " << text << endl;
  98. }
  99. void debugPrint(const string& text)
  100. {
  101. if (debug)
  102. cout << " " << text << endl;
  103. }
  104. void readMasterConfig1(const string& fn, KindConfig& conf)
  105. {
  106. verbosePrint("reading master config " + fn);
  107. conf.addFile(fn);
  108. }
  109. void readMasterConfig(const string& fn, KindConfig& conf)
  110. {
  111. if (!fn.empty()) // master config given by user on commandline
  112. readMasterConfig1(fn, conf);
  113. else if (fileExists("/etc/kind/master.conf"))
  114. readMasterConfig1("/etc/kind/master.conf", conf);
  115. else if (fileExists("/ffp/etc/kind/master.conf"))
  116. readMasterConfig1("/ffp/etc/kind/master.conf", conf);
  117. else
  118. throw Exception("MasterConfig", "no file");
  119. }
  120. string findVault(const string& v)
  121. {
  122. bool found = false;
  123. FileName fn;
  124. fn.setName(v);
  125. for (unsigned int i = 0; !found && i < banks.size(); ++i)
  126. {
  127. fn.setPath(banks[i]);
  128. if (dirExists(fn.getFileName()))
  129. found = true;
  130. }
  131. if (!found)
  132. throw Exception("find vault", v + " not found");
  133. verbosePrint("using vault " + fn.getFileName());
  134. return fn.getFileName();
  135. }
  136. void readVaultConfig(const string& vault, KindConfig& conf)
  137. {
  138. string vaultpath = findVault(vault);
  139. const string& vaultConfigName = vaultpath + '/' + conf.getString("vaultConfigName");
  140. verbosePrint("reading vault config:");
  141. verbosePrint(" " + vaultConfigName);
  142. conf.addFile(vaultConfigName);
  143. }
  144. string getImageName(const KindConfig& conf,
  145. const string& vaultPath,
  146. const DateTime& imageTime)
  147. {
  148. bool nonPortable = false;
  149. string imageName = conf.getString("imageName");
  150. for (unsigned int i = 0; !nonPortable && i < imageName.size(); ++i)
  151. {
  152. char c = imageName[i];
  153. if (!isalnum(c) && c != '.' && c != '_')
  154. nonPortable = true;
  155. }
  156. if (nonPortable)
  157. throw Exception("getImageName", "Invalid character in image name " + imageName);
  158. if (!imageName.empty())
  159. imageName += '-';
  160. string imageFullName = vaultPath + "/" + imageName ;
  161. if (conf.getBool("longImageName"))
  162. imageFullName += imageTime.getString('m');
  163. else
  164. imageFullName += imageTime.getString('s');
  165. return imageFullName;
  166. }
  167. Images findImages(const string& vaultpath, const KindConfig& conf, bool all)
  168. {
  169. Strings dirs;
  170. debugPrint("searching images in " + vaultpath);
  171. dirList(vaultpath, dirs);
  172. Images imageList;
  173. for (string dir : dirs)
  174. {
  175. FileName fn(dir);
  176. string imgname = conf.getString("imageName");
  177. if (startsWith(fn.getName(), imgname))
  178. {
  179. debugPrint("Checking " + dir);
  180. Image image(dir);
  181. if (all || image.valid)
  182. imageList.push_back(image);
  183. }
  184. }
  185. if (imageList.size() > 1)
  186. sort(imageList.begin(), imageList.end());
  187. return imageList;
  188. }
  189. void listImageInfo(const string& vault,
  190. KindConfig conf /*Copy!*/ ,
  191. const DateTime& imageTime,
  192. const string& backupSet)
  193. {
  194. readVaultConfig(vault, conf);
  195. string vaultPath = findVault(vault);
  196. Images imageList = findImages(vaultPath, conf, true);
  197. cout << "== " << vault << " ==" << endl;
  198. for (auto img : imageList)
  199. {
  200. if (img.series == backupSet || backupSet.empty())
  201. {
  202. img.printInfo();
  203. cout << "---" << endl;
  204. }
  205. }
  206. }
  207. void doBackup(const string& vault,
  208. const string& imageFullName,
  209. const string& referenceImage,
  210. const KindConfig& conf)
  211. {
  212. // create image path
  213. bool shellMode = true;
  214. // create source descriptor
  215. string host;
  216. if (conf.hasKey("host"))
  217. host = conf.getString("host");
  218. string server;
  219. if (conf.hasKey("server"))
  220. {
  221. server = conf.getString("server");
  222. shellMode = false;
  223. }
  224. if (!host.empty() && !server.empty())
  225. throw Exception("backupVault", "Cannot have host and server");
  226. if (host.empty() && server.empty())
  227. throw Exception("backupVault", "No host or server specified");
  228. // ping host / server
  229. // ping -c 1 -W 5 -q $HOST
  230. string pingCommand = conf.getString("ping");
  231. debugPrint("PingCommand: " + pingCommand);
  232. if (!pingCommand.empty())
  233. {
  234. if (!host.empty())
  235. replacePlaceHolder(pingCommand, "%host", host);
  236. else
  237. replacePlaceHolder(pingCommand, "%host", server);
  238. int rc = 0;
  239. Strings pingResult = localExec(pingCommand, rc, debug);
  240. if (rc != 0)
  241. throw Exception("Host not available", pingCommand);
  242. }
  243. string path = conf.getString("path");
  244. if (path.empty())
  245. throw Exception("rsync", "empty source path");
  246. if (path.back() != '/')
  247. path += '/';
  248. string rsyncCmd = "rsync -vrltH --delete --stats -D --numeric-ids ";
  249. if (!conf.getBool("ignorePermission"))
  250. rsyncCmd += "-pgo";
  251. vector<string> rso = conf.getStrings("rsyncOption");
  252. for (const string& opt : rso)
  253. rsyncCmd += opt + " ";
  254. // excludes
  255. Strings excluded = getExclusions(conf, shellMode);
  256. // create image path
  257. if (!dryRun)
  258. if (mkdir(imageFullName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
  259. throw Exception("Create image", "failed to create " + imageFullName);
  260. // error message
  261. // we write an generic error message to mark backup as unsuccessful
  262. // will be deleted at successful end of rsync
  263. string errorfile = imageFullName + "/error";
  264. if (!dryRun)
  265. {
  266. ofstream error(errorfile);
  267. error << "failed" << endl;
  268. error.close();
  269. }
  270. if (shellMode) // shell mode
  271. {
  272. // cout << "USING SHELLMODE '" << host << "'" << endl;
  273. string remoteShell = conf.getString("remoteShell");
  274. string userAtHost = conf.getString("user") + "@" + conf.getString("host");
  275. string rshCommand = remoteShell;
  276. if (remoteShell.empty())
  277. rshCommand = "ssh";
  278. rshCommand += " " + userAtHost;
  279. if (!dryRun)
  280. strings2File(excluded, imageFullName + "/exclude");
  281. // rsync image
  282. if (!remoteShell.empty())
  283. rsyncCmd += " -e \'" + remoteShell + "\' ";
  284. rsyncCmd += "--exclude-from=" + imageFullName + "/exclude ";
  285. if (!referenceImage.empty())
  286. rsyncCmd += "--link-dest=" + referenceImage + "/tree ";
  287. rsyncCmd += userAtHost + ":" + path + " ";
  288. rsyncCmd += imageFullName + "/tree";
  289. } // shell mode
  290. else
  291. {
  292. // cout << "USING SERVERMODE" << endl;
  293. // we cannot use find without shell access
  294. // and do not read an exclude file on client side
  295. if (!dryRun)
  296. strings2File(excluded, imageFullName + "/exclude");
  297. rsyncCmd += "--exclude-from=" + imageFullName + "/exclude ";
  298. if (!referenceImage.empty())
  299. rsyncCmd += "--link-dest=" + referenceImage + "/tree ";
  300. rsyncCmd += conf.getString("server") + "::" + path + " ";
  301. rsyncCmd += imageFullName + "/tree";
  302. }
  303. debugPrint("Action: " + rsyncCmd);
  304. vector<string> backupResult;
  305. if (!dryRun)
  306. {
  307. verbosePrint("syncing (" + rsyncCmd + ")");
  308. int rc;
  309. backupResult = localExec(rsyncCmd, rc, debug, imageFullName + "/rsync-log");
  310. if (rc == 0 ||
  311. rc == 24 || // "no error" or "vanished source files" (ignored)
  312. rc == 6144) // workaround for wrong exit code ??!!
  313. {
  314. unlink(errorfile.c_str());
  315. long int st = 0;
  316. long int sc = 0;
  317. for (auto bl : backupResult)
  318. {
  319. if (startsWith(bl, "Total file size"))
  320. st = getNumber(bl);
  321. else if (startsWith(bl, "Total transferred file size"))
  322. sc = getNumber(bl);
  323. }
  324. // sizes[vault] = pair<long int, long int>(st, sc);
  325. sizes[vault] = Sizes(st, sc);
  326. // cout << vault << " " << st << " || " << sc << endl;
  327. }
  328. else
  329. throw Exception("Backup", "Failed to execute rsync (result: " + to_string(rc) + ")");
  330. }
  331. else
  332. cout << "Not executing " << rsyncCmd << endl;
  333. }
  334. bool backupVault(const string& vault,
  335. KindConfig conf /*Copy!*/ ,
  336. const DateTime& imageTime,
  337. bool fullImage,
  338. const string& forcedBackupSet)
  339. {
  340. if (!quiet)
  341. cout << DateTime::now().getString('h') << ": Backup of vault " << vault << endl;
  342. try
  343. {
  344. readVaultConfig(vault, conf);
  345. // where to store
  346. string vaultPath = findVault(vault);
  347. // image path
  348. string imageFullName = getImageName(conf, vaultPath, imageTime);
  349. bool backupNow = true;
  350. // existing images
  351. Images validImageList = findImages(vaultPath, conf, false);
  352. string currentSet = "expire"; // we are not using backupSets
  353. // check if we are using backup sets
  354. map<string, int> setIdx;
  355. vector<SetRule> backupSetRule;
  356. int setRuleIdx = -1;
  357. if (conf.hasKey("setRule"))
  358. {
  359. readSetRules(conf, setIdx, backupSetRule);
  360. if (!setIdx.empty())
  361. {
  362. if (forcedBackupSet.empty())
  363. {
  364. backupNow = false;
  365. // find time for nextBackup for every backupSet
  366. // defaults to now == imageTime;
  367. vector<DateTime> nextBackup(backupSetRule.size(), imageTime);
  368. // find time for next backup
  369. for (const Image& image : validImageList)
  370. {
  371. if (image.series != "expire")
  372. {
  373. string s = image.series;
  374. if (setIdx.count(s) > 0) // rule for set exists?
  375. {
  376. int rIdx = setIdx[s];
  377. // image is valid for this and "lower level" backupSets
  378. for (unsigned int i = rIdx; i < backupSetRule.size(); ++i)
  379. if (nextBackup[i] < image.time + backupSetRule[i].distance)
  380. nextBackup[i] = image.time + backupSetRule[i].distance;
  381. }
  382. }
  383. }
  384. if (debug)
  385. for (unsigned int i = 0; i < backupSetRule.size(); ++i)
  386. cout << " Next backup for " << backupSetRule[i].name << " at " << nextBackup[i].getString('h') << endl;
  387. // find backupSet that
  388. // - needs backup
  389. // - has longest time to keep
  390. // because of ordered list backupSetRule this is the first set, that need
  391. currentSet = "";
  392. for (unsigned int i = 0; i < backupSetRule.size() && currentSet.empty(); ++i)
  393. {
  394. string name = backupSetRule[i].name;
  395. if (nextBackup[i] <= imageTime + 5) // small offset of 5s for "jitter"
  396. {
  397. backupNow = true;
  398. currentSet = name;
  399. setRuleIdx = i;
  400. }
  401. }
  402. }
  403. else
  404. {
  405. if (setIdx.count(forcedBackupSet) > 0)
  406. {
  407. currentSet = forcedBackupSet;
  408. setRuleIdx = setIdx[forcedBackupSet];
  409. }
  410. else
  411. throw Exception("force backup of set " + forcedBackupSet, " set not exists");
  412. }
  413. } // if (!setIdx.empty())
  414. } // (conf.hasKey("setRule"))
  415. if (backupNow)
  416. {
  417. verbosePrint("backup to \"" + imageFullName + "\"");
  418. if (setRuleIdx >= 0 && !quiet)
  419. cout << " backup set is \"" << currentSet << "\"" << endl;
  420. }
  421. else if (!quiet)
  422. cout << " no backup set needs update" << endl;
  423. if (backupNow)
  424. {
  425. // find reference image
  426. string referenceImage;
  427. if (!fullImage)
  428. {
  429. if (validImageList.empty())
  430. throw Exception("backupVault", "no reference image found");
  431. // last image is newest image
  432. referenceImage = validImageList.back().name;
  433. }
  434. doBackup(vault, imageFullName, referenceImage, conf);
  435. if (!dryRun)
  436. {
  437. string lastPath = vaultPath + "/last";
  438. struct stat fstat;
  439. // remove last (dir or symlink)
  440. if (lstat(lastPath.c_str(), &fstat) == 0) // last exists
  441. {
  442. if (S_ISDIR(fstat.st_mode))
  443. removeDir(lastPath);
  444. else
  445. unlink(lastPath.c_str());
  446. }
  447. string linkType = conf.getString("lastLink");
  448. if (linkType == "hardLink")
  449. {
  450. int rc;
  451. string hardLinkCommand = "cp -al " + imageFullName + " " + lastPath;
  452. Strings res = localExec(hardLinkCommand, rc, debug);
  453. }
  454. else if (linkType == "symLink")
  455. {
  456. // set symlink to last image
  457. symlink(imageFullName.c_str(), lastPath.c_str());
  458. }
  459. else if (linkType != "null")
  460. cerr << "invalid Value in \"lastLink\"" << endl;
  461. // write expire date to file
  462. DateTime expireTime;
  463. string rule;
  464. if (setRuleIdx < 0) // not backup set based
  465. expireTime = getExpireDate(imageTime, conf, rule);
  466. else
  467. {
  468. expireTime = imageTime + backupSetRule[setRuleIdx].keep;
  469. rule = backupSetRule[setRuleIdx].rule;
  470. }
  471. ofstream expireFile(imageFullName + "/expires");
  472. expireFile << currentSet << "-" << expireTime.getString('m') << endl;
  473. expireFile << rule << endl;
  474. }
  475. }
  476. return backupNow;
  477. }
  478. catch (Exception ex)
  479. {
  480. cerr << "Exception in vault " << vault << ": " << ex.what() << endl;
  481. return false;
  482. }
  483. }
  484. void expireVault(const string& vault, KindConfig conf, DateTime now)
  485. {
  486. if (!quiet)
  487. cout << DateTime::now().getString('h') << ": Expiring images in vault " << vault << endl;
  488. readVaultConfig(vault, conf);
  489. string vaultpath = findVault(vault);
  490. Images imagelist = findImages(vaultpath, conf, true);
  491. string lastValidImage;
  492. for (Image image : imagelist)
  493. {
  494. if (image.valid)
  495. lastValidImage = image.name;
  496. }
  497. for (Image image : imagelist)
  498. {
  499. if (debug)
  500. image.printInfo();
  501. DateTime imageTime = image.time;
  502. if (imageTime != now && // ignore just created image
  503. image.name != lastValidImage // ignore last valid image
  504. )
  505. {
  506. DateTime expireTime;
  507. string expireRule;
  508. if (!image.valid) // invalid image?
  509. {
  510. time_t expPeriod = stot(conf.getString("expireFailedImage"));
  511. if (expPeriod < 0)
  512. throw Exception("expireFailedImage", "Time period must be positive");
  513. expireTime = imageTime + stot(conf.getString("expireFailedImage"));
  514. expireRule = "invalid image: " + conf.getString("expireFailedImage");
  515. debugPrint("- invalid image");
  516. }
  517. else
  518. {
  519. debugPrint("- valid image");
  520. expireTime = image.expire;
  521. expireRule = image.expireRule;
  522. }
  523. if (expireTime < now)
  524. {
  525. if (!quiet)
  526. cout << " removing image " << image.name << endl;
  527. try
  528. {
  529. if (removeDir(image.name) != 0)
  530. cout << "Error removing " << image.name << endl;
  531. }
  532. catch (Exception ex)
  533. {
  534. cerr << "Exception: " << ex.what() << endl;
  535. }
  536. }
  537. }
  538. else
  539. debugPrint("- current image - ignored");
  540. }
  541. }
  542. /*AppGen:Main*/
  543. int main(int argc, char* argv[])
  544. {
  545. /*AppGen:MainEnd*/
  546. int exitCode = 0;
  547. string lockFile;
  548. try
  549. {
  550. // handling of parameters and switches
  551. if (debug) // debug implies verbose
  552. verbose = true;
  553. if (!doBackup && !doExpire && !listConfig && !listImages)
  554. {
  555. doBackup = true;
  556. doExpire = true;
  557. }
  558. KindConfig conf;
  559. // default-values
  560. conf.add("imageName", "image");
  561. conf.add("vaultConfigName", "kind/vault.conf");
  562. conf.add("expireFailedImage", "3 days");
  563. conf.add("expireRule", "* * * * 1 month");
  564. conf.add("ping", "ping -c 1 -W 5 %host");
  565. conf.add("rsyncOption", ""); // no additional rsync option
  566. conf.add("remoteShell", "");
  567. conf.add("lockfile", "/var/lock/kind");
  568. conf.add("userExcludeFile", "nobackup.list");
  569. conf.add("userExcludeCommand",
  570. "find %path -type f -iname '*nobackup' -printf '%P\\\\n'");
  571. conf.add("logSize", "");
  572. conf.add("lastLink", "symLink");
  573. if (listConfig)
  574. {
  575. cout << "builtin config" << endl;
  576. conf.print(". ");
  577. }
  578. readMasterConfig(masterConfig, conf);
  579. banks = conf.getStrings("bank");
  580. if (banks.empty())
  581. throw Exception("read master configuration", "no banks defined");
  582. vector<string> vaults;
  583. string groupname = "group_" + vault;
  584. if (conf.hasKey(groupname))
  585. {
  586. vaults = conf.getStrings(groupname);
  587. vault.clear(); // no single vault but group
  588. }
  589. else
  590. vaults.push_back(vault);
  591. if (listConfig)
  592. {
  593. cout << "global config:" << endl;
  594. conf.print(". ");
  595. if (!vault.empty())
  596. {
  597. readVaultConfig(vault, conf);
  598. cout << "vault config:" << endl;
  599. conf.print(". ");
  600. }
  601. else
  602. cout << "specify single vault (not group) to see vault config" << endl;
  603. exit(0);
  604. }
  605. DateTime imageTime = DateTime::now();
  606. if (listImages)
  607. {
  608. for (string vault : vaults)
  609. listImageInfo(vault, conf, imageTime, forcedBackupSet);
  610. exit(0);
  611. }
  612. // previous actions do not need locking
  613. lockFile = conf.getString("lockfile");
  614. createLock(lockFile);
  615. string logSizeFile = conf.getString("logSize");
  616. readSizes(logSizeFile);
  617. for (string vault : vaults)
  618. {
  619. if (doBackup)
  620. if (backupVault(vault, conf, imageTime, fullImage, forcedBackupSet))
  621. writeSizes(logSizeFile);
  622. if (doExpire)
  623. expireVault(vault, conf, imageTime);
  624. }
  625. if (!quiet)
  626. cout << DateTime::now().getString('h') << ": finished" << endl;
  627. }
  628. catch (const Exception& ex)
  629. {
  630. cerr << "Exception: " << ex.what() << endl;
  631. exitCode = 1;
  632. }
  633. catch (const char* msg)
  634. {
  635. cerr << "Exception(char*): " << msg << endl;
  636. exitCode = 1;
  637. }
  638. catch (const string& msg)
  639. {
  640. cerr << "Exception(string): " << msg << endl;
  641. exitCode = 1;
  642. }
  643. removeLock(lockFile);
  644. return exitCode;
  645. }