diff options
| author | 2011-04-27 22:39:48 +0200 | |
|---|---|---|
| committer | 2011-04-27 22:39:48 +0200 | |
| commit | 2e1f4c9002a7156230173113ed95d1464c59cfe6 (patch) | |
| tree | 142b7d10ff6e037a7f239e7cda2b58c27676ebed | |
| parent | 9f59aa35933f16e893ae31551c19a57744aa9d8a (diff) | |
| download | libimobiledevice-2e1f4c9002a7156230173113ed95d1464c59cfe6.tar.gz libimobiledevice-2e1f4c9002a7156230173113ed95d1464c59cfe6.tar.bz2 | |
idevicebackup2: Add command line argument flags for restore command
| -rw-r--r-- | tools/idevicebackup2.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index 8ad8355..ff31189 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c | |||
| @@ -71,6 +71,13 @@ enum plist_format_t { | |||
| 71 | PLIST_FORMAT_BINARY | 71 | PLIST_FORMAT_BINARY |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | enum cmd_flags { | ||
| 75 | CMD_FLAG_RESTORE_SYSTEM_FILES = 0, | ||
| 76 | CMD_FLAG_RESTORE_REBOOT = (1 << 1), | ||
| 77 | CMD_FLAG_RESTORE_DONT_COPY_BACKUP = (1 << 2), | ||
| 78 | CMD_FLAG_RESTORE_SETTINGS = (1 << 3) | ||
| 79 | }; | ||
| 80 | |||
| 74 | static void notify_cb(const char *notification, void *userdata) | 81 | static void notify_cb(const char *notification, void *userdata) |
| 75 | { | 82 | { |
| 76 | if (!strcmp(notification, NP_SYNC_CANCEL_REQUEST)) { | 83 | if (!strcmp(notification, NP_SYNC_CANCEL_REQUEST)) { |
| @@ -1063,11 +1070,15 @@ static void print_usage(int argc, char **argv) | |||
| 1063 | { | 1070 | { |
| 1064 | char *name = NULL; | 1071 | char *name = NULL; |
| 1065 | name = strrchr(argv[0], '/'); | 1072 | name = strrchr(argv[0], '/'); |
| 1066 | printf("Usage: %s [OPTIONS] CMD DIRECTORY\n", (name ? name + 1: argv[0])); | 1073 | printf("Usage: %s [OPTIONS] CMD [CMDOPTIONS] DIRECTORY\n", (name ? name + 1: argv[0])); |
| 1067 | printf("Create or restore backup from the current or specified directory.\n\n"); | 1074 | printf("Create or restore backup from the current or specified directory.\n\n"); |
| 1068 | printf("commands:\n"); | 1075 | printf("commands:\n"); |
| 1069 | printf(" backup\tcreate backup for the device\n"); | 1076 | printf(" backup\tcreate backup for the device\n"); |
| 1070 | printf(" restore\trestore last backup to the device\n"); | 1077 | printf(" restore\trestore last backup to the device\n"); |
| 1078 | printf(" --system\trestore system files, too.\n"); | ||
| 1079 | printf(" --reboot\treboot the system when done.\n"); | ||
| 1080 | printf(" --nocopy\tdo not copy backup folder before restoring.\n"); | ||
| 1081 | printf(" --settings\trestore device settings from the backup.\n"); | ||
| 1071 | printf(" info\t\tshow details about last completed backup of device\n"); | 1082 | printf(" info\t\tshow details about last completed backup of device\n"); |
| 1072 | printf(" list\t\tlist files of last completed backup in CSV format\n"); | 1083 | printf(" list\t\tlist files of last completed backup in CSV format\n"); |
| 1073 | printf(" unback\tUnpack a completed backup in DIRECTORY/_unback_/\n\n"); | 1084 | printf(" unback\tUnpack a completed backup in DIRECTORY/_unback_/\n\n"); |
| @@ -1086,11 +1097,13 @@ int main(int argc, char *argv[]) | |||
| 1086 | uint16_t port = 0; | 1097 | uint16_t port = 0; |
| 1087 | uuid[0] = 0; | 1098 | uuid[0] = 0; |
| 1088 | int cmd = -1; | 1099 | int cmd = -1; |
| 1100 | int cmd_flags = 0; | ||
| 1089 | int is_full_backup = 0; | 1101 | int is_full_backup = 0; |
| 1090 | char *backup_directory = NULL; | 1102 | char *backup_directory = NULL; |
| 1091 | struct stat st; | 1103 | struct stat st; |
| 1092 | plist_t node_tmp = NULL; | 1104 | plist_t node_tmp = NULL; |
| 1093 | plist_t info_plist = NULL; | 1105 | plist_t info_plist = NULL; |
| 1106 | plist_t opts = NULL; | ||
| 1094 | mobilebackup2_error_t err; | 1107 | mobilebackup2_error_t err; |
| 1095 | 1108 | ||
| 1096 | /* we need to exit cleanly on running backups and restores or we cause havok */ | 1109 | /* we need to exit cleanly on running backups and restores or we cause havok */ |
| @@ -1124,6 +1137,18 @@ int main(int argc, char *argv[]) | |||
| 1124 | else if (!strcmp(argv[i], "restore")) { | 1137 | else if (!strcmp(argv[i], "restore")) { |
| 1125 | cmd = CMD_RESTORE; | 1138 | cmd = CMD_RESTORE; |
| 1126 | } | 1139 | } |
| 1140 | else if (!strcmp(argv[i], "--system")) { | ||
| 1141 | cmd_flags |= CMD_FLAG_RESTORE_SYSTEM_FILES; | ||
| 1142 | } | ||
| 1143 | else if (!strcmp(argv[i], "--reboot")) { | ||
| 1144 | cmd_flags |= CMD_FLAG_RESTORE_REBOOT; | ||
| 1145 | } | ||
| 1146 | else if (!strcmp(argv[i], "--nocopy")) { | ||
| 1147 | cmd_flags |= CMD_FLAG_RESTORE_DONT_COPY_BACKUP; | ||
| 1148 | } | ||
| 1149 | else if (!strcmp(argv[i], "--settings")) { | ||
| 1150 | cmd_flags |= CMD_FLAG_RESTORE_SETTINGS; | ||
| 1151 | } | ||
| 1127 | else if (!strcmp(argv[i], "info")) { | 1152 | else if (!strcmp(argv[i], "info")) { |
| 1128 | cmd = CMD_INFO; | 1153 | cmd = CMD_INFO; |
| 1129 | verbose = 0; | 1154 | verbose = 0; |
| @@ -1369,8 +1394,18 @@ checkpoint: | |||
| 1369 | 1394 | ||
| 1370 | PRINT_VERBOSE(1, "Starting Restore...\n"); | 1395 | PRINT_VERBOSE(1, "Starting Restore...\n"); |
| 1371 | 1396 | ||
| 1372 | plist_t opts = plist_new_dict(); | 1397 | opts = plist_new_dict(); |
| 1373 | plist_dict_insert_item(opts, "shouldRestoreSystemFiles", plist_new_bool(0)); | 1398 | plist_dict_insert_item(opts, "RestoreSystemFiles", plist_new_bool(cmd_flags & CMD_FLAG_RESTORE_SYSTEM_FILES)); |
| 1399 | PRINT_VERBOSE(1, "Restoring system files: %s\n", (cmd_flags & CMD_FLAG_RESTORE_SYSTEM_FILES ? "Yes":"No")); | ||
| 1400 | if ((cmd_flags & CMD_FLAG_RESTORE_REBOOT) == 0) | ||
| 1401 | plist_dict_insert_item(opts, "RestoreShouldReboot", plist_new_bool(0)); | ||
| 1402 | PRINT_VERBOSE(1, "Rebooting after restore: %s\n", (cmd_flags & CMD_FLAG_RESTORE_REBOOT ? "Yes":"No")); | ||
| 1403 | if (cmd_flags & CMD_FLAG_RESTORE_DONT_COPY_BACKUP) | ||
| 1404 | plist_dict_insert_item(opts, "RestoreDontCopyBackup", plist_new_bool(1)); | ||
| 1405 | PRINT_VERBOSE(1, "Don't copy backup: %s\n", (cmd_flags & CMD_FLAG_RESTORE_DONT_COPY_BACKUP ? "Yes":"No")); | ||
| 1406 | plist_dict_insert_item(opts, "RestorePreserveSettings", plist_new_bool((cmd_flags & CMD_FLAG_RESTORE_SETTINGS) == 0)); | ||
| 1407 | PRINT_VERBOSE(1, "Preserve settings of device: %s\n", ((cmd_flags & CMD_FLAG_RESTORE_SETTINGS) == 0 ? "Yes":"No")); | ||
| 1408 | |||
| 1374 | err = mobilebackup2_send_request(mobilebackup2, "Restore", uuid, uuid, opts); | 1409 | err = mobilebackup2_send_request(mobilebackup2, "Restore", uuid, uuid, opts); |
| 1375 | plist_free(opts); | 1410 | plist_free(opts); |
| 1376 | if (err != MOBILEBACKUP2_E_SUCCESS) { | 1411 | if (err != MOBILEBACKUP2_E_SUCCESS) { |
