+ string backup_dest = "", backup_script = "";
+ string localdb_dir = "";
+ string backup_scheme = "";
+ string signature_filter = "";
+
+ string tmp_dir = "/tmp";
+ if (getenv("TMPDIR") != NULL)
+ tmp_dir = getenv("TMPDIR");
+
+ while (1) {
+ static struct option long_options[] = {
+ {"localdb", 1, 0, 0}, // 0
+ {"exclude", 1, 0, 0}, // 1
+ {"filter", 1, 0, 0}, // 2
+ {"filter-extension", 1, 0, 0}, // 3
+ {"dest", 1, 0, 0}, // 4
+ {"scheme", 1, 0, 0}, // 5
+ {"signature-filter", 1, 0, 0}, // 6
+ {"intent", 1, 0, 0}, // 7
+ {"full-metadata", 0, 0, 0}, // 8
+ {"tmpdir", 1, 0, 0}, // 9
+ {"upload-script", 1, 0, 0}, // 10
+ {"rebuild-statcache", 0, 0, 0}, // 11
+ // Aliases for short options
+ {"verbose", 0, 0, 'v'},
+ {NULL, 0, 0, 0},
+ };
+
+ int long_index;
+ int c = getopt_long(argc, argv, "v", long_options, &long_index);
+
+ if (c == -1)
+ break;
+
+ if (c == 0) {
+ switch (long_index) {
+ case 0: // --localdb
+ localdb_dir = optarg;
+ break;
+ case 1: // --exclude
+ if (optarg[0] != '/')
+ excludes.push_back(optarg);
+ else
+ excludes.push_back(optarg + 1);
+ break;
+ case 2: // --filter
+ filter_program = optarg;
+ break;
+ case 3: // --filter-extension
+ filter_extension = optarg;
+ break;
+ case 4: // --dest
+ backup_dest = optarg;
+ break;
+ case 5: // --scheme
+ backup_scheme = optarg;
+ break;
+ case 6: // --signature-filter
+ signature_filter = optarg;
+ break;
+ case 7: // --intent
+ snapshot_intent = atof(optarg);
+ if (snapshot_intent <= 0)
+ snapshot_intent = 1;
+ break;
+ case 8: // --full-metadata
+ flag_full_metadata = true;
+ break;
+ case 9: // --tmpdir
+ tmp_dir = optarg;
+ break;
+ case 10: // --upload-script
+ backup_script = optarg;
+ break;
+ case 11: // --rebuild-statcache
+ flag_rebuild_statcache = true;
+ break;
+ default:
+ fprintf(stderr, "Unhandled long option!\n");
+ return 1;
+ }
+ } else {
+ switch (c) {
+ case 'v':
+ verbose = true;
+ break;
+ default:
+ usage(argv[0]);
+ return 1;
+ }
+ }
+ }
+
+ if (optind == argc) {
+ usage(argv[0]);
+ return 1;
+ }
+
+ searches.push_back(".");
+ for (int i = optind; i < argc; i++)
+ add_include(argv[i]);
+
+ if (backup_dest == "" && backup_script == "") {
+ fprintf(stderr,
+ "Error: Backup destination must be specified using --dest= or --upload-script=\n");
+ usage(argv[0]);
+ return 1;
+ }
+
+ if (backup_dest != "" && backup_script != "") {
+ fprintf(stderr,
+ "Error: Cannot specify both --dest= and --upload-script=\n");
+ usage(argv[0]);
+ return 1;
+ }
+
+ // Default for --localdb is the same as --dest
+ if (localdb_dir == "") {
+ localdb_dir = backup_dest;
+ }
+ if (localdb_dir == "") {
+ fprintf(stderr,
+ "Error: Must specify local database path with --localdb=\n");
+ usage(argv[0]);
+ return 1;
+ }
+