Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/cmd/fossil/dump.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 * Clumsy hack to take snapshots and dumps.
3
 */
4
#include <u.h>
5
#include <libc.h>
6
 
7
void
8
usage(void)
9
{
10
	fprint(2, "usage: fossil/dump [-i snap-interval] [-n name] fscons /n/fossil\n");
11
	exits("usage");
12
}
13
 
14
char*
15
snapnow(void)
16
{
17
	Tm t;
18
	static char buf[100];
19
 
20
	t = *localtime(time(0)-5*60*60);	/* take dumps at 5:00 am */
21
 
22
	sprint(buf, "archive/%d/%02d%02d", t.year+1900, t.mon+1, t.mday);
23
	return buf;
24
}
25
 
26
void
27
main(int argc, char **argv)
28
{
29
	int onlyarchive, cons, s;
30
	ulong t, i;
31
	char *name;
32
 
33
	name = "main";
34
	s = 0;
35
	onlyarchive = 0;
36
	i = 60*60;		/* one hour */
37
	ARGBEGIN{
38
	case 'i':
39
		i = atoi(EARGF(usage()));
40
		if(i == 0){
41
			onlyarchive = 1;
42
			i = 60*60;
43
		}
44
		break;
45
	case 'n':
46
		name = EARGF(usage());
47
		break;
48
	case 's':
49
		s = atoi(EARGF(usage()));
50
		break;
51
	}ARGEND
52
 
53
	if(argc != 2)
54
		usage();
55
 
56
	if((cons = open(argv[0], OWRITE)) < 0)
57
		sysfatal("open %s: %r", argv[0]);
58
 
59
	if(chdir(argv[1]) < 0)
60
		sysfatal("chdir %s: %r", argv[1]);
61
 
62
	rfork(RFNOTEG);
63
	switch(fork()){
64
	case -1:
65
		sysfatal("fork: %r");
66
	case 0:
67
		break;
68
	default:
69
		exits(0);
70
	}
71
 
72
	/*
73
	 * pause at boot time to let clock stabilize.
74
	 */
75
	if(s)
76
		sleep(s*1000);
77
 
78
	for(;;){
79
		if(access(snapnow(), AEXIST) < 0)
80
			fprint(cons, "\nfsys %s snap -a\n", name);
81
		t = time(0);
82
		sleep((i - t%i)*1000+200);
83
		if(!onlyarchive)
84
			fprint(cons, "\nfsys %s snap\n", name);
85
	}
86
}