/
backup.c
51 lines (39 loc) · 868 Bytes
/
backup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <pkg.h>
#include <sysexits.h>
#include "pkgcli.h"
void
usage_backup(void)
{
fprintf(stderr, "usage: pkg backup -[d|r] dest\n");
fprintf(stderr, "For more information see 'pkg help backup'.\n");
}
int
exec_backup(int argc, char **argv)
{
struct pkgdb *db;
char *dest = NULL;
if (argc < 2 || argc > 3 || argv[1][0] != '-') {
usage_backup();
return (EX_USAGE);
}
if (argc == 3)
dest = argv[2];
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
return (EX_IOERR);
if (argv[1][1] == 'd') {
printf("Dumping database...");
fflush(stdout);
if (pkgdb_dump(db, dest) == EPKG_FATAL)
return (EPKG_FATAL);
printf("done\n");
}
if (argv[1][1] == 'r') {
printf("Restoring database...");
fflush(stdout);
if (pkgdb_load(db, dest) == EPKG_FATAL)
return (EPKG_FATAL);
printf("done\n");
}
pkgdb_close(db);
return (EPKG_OK);
}