2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <androidfw/BackupHelpers.h>
18 #include <utils/String8.h>
24 using namespace android;
29 usage(int argc, const char** argv)
31 const char* p = argv[0];
33 fprintf(stderr, "%s: Backs up your data.\n"
36 " Prints all of the data that can be backed up to stdout.\n"
38 "usage: %s list FILE\n"
39 " Lists the backup entities in the file.\n"
41 "usage: %s print NAME FILE\n"
42 " Prints the entity named NAME in FILE.\n",
50 printf("this would have written all of your data to stdout\n");
55 perform_list(const char* filename)
60 fd = open(filename, O_RDONLY);
62 fprintf(stderr, "Error opening: %s\n", filename);
66 BackupDataReader reader(fd);
70 while (reader.ReadNextHeader(&done, &type) == 0) {
75 case BACKUP_HEADER_ENTITY_V1:
79 err = reader.ReadEntityHeader(&key, &dataSize);
81 printf(" entity: %s (%d bytes)\n", key.string(), dataSize);
83 printf(" Error reading entity header\n");
89 printf("Unknown chunk type: 0x%08x\n", type);
98 int perform_print(const char* entityname, const char* filename)
100 printf("perform_print(%s, %s);", entityname, filename);
105 main(int argc, const char** argv)
108 return perform_full_backup();
110 if (argc == 3 && 0 == strcmp(argv[1], "list")) {
111 return perform_list(argv[2]);
113 if (argc == 4 && 0 == strcmp(argv[1], "print")) {
114 return perform_print(argv[2], argv[3]);
116 return usage(argc, argv);