-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbScheduler.cpp
More file actions
141 lines (117 loc) · 4.01 KB
/
fbScheduler.cpp
File metadata and controls
141 lines (117 loc) · 4.01 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* $Id: fbScheduler.cpp,v 1.21 2008/04/23 01:42:26 ctubbsii Exp $ */
#include "fbScheduler.h"
#define bk_path "/var/flashback/" ///< set path to backup location... this should be comming from config...
fbScheduler::fbScheduler(fbData* _data):fbThread(_data), data(_data)
{
data->debug(NONE, "fbScheduler.this");
}
fbScheduler::~fbScheduler()
{
data->debug(NONE, "fbScheduler.~this");
shutdown();
}
void fbScheduler::startup()
{
start();
}
void fbScheduler::shutdown()
{
stop();
}
void fbScheduler::run()
{
string desc, path;
fbDate date;
fbTime time;
int repeatval, index;
Repeat_type repeat;
bool ret;
while(!isStopping())
{
//Backup query
data->queryBackups();
do
{
ret = data->db->getBackupRow(desc, date, time, path, &repeat,
&repeatval, &index);
if(ret)
{
struct stat st;
//re sync time/date
time.setTicksLocal();
date.setJulianLocal();
//backup!?!
data->debug(NONE, "Backing up: %d %s: %s at %ld %ld %d %d", index,
desc.c_str(), path.c_str(), time.getTicks(), date.getJulian(),
repeat, repeatval);
//do the backup here!
char buff[1024*4];
snprintf(buff, sizeof(buff)-1, "%s%ld%ld%d.tar.bz2", bk_path, date.getJulian(), time.getTicks(), index);
string msg = buff;
/* check if source path exists
* For external drives, this may not be true at this time
* If path doesn't exist, we can't back up just yet
* It will have to wait until path exists (drive is mounted)
* Perhaps next poll? */
if (lstat(path.c_str(), &st) < 0)
data->debug(NONE, "Source path not accessible. Can't back this up right now: %s", path.c_str());
else
{
data->db->addRepo(desc, date, time, path, msg);
new fbBackup(data, path, msg);
//test repeat!
data->db->deleteRow("backup", index);
switch(repeat)
{
case MINS:
time.addMin(repeatval);
//need to check for day overflow!
data->db->addBackupJob(desc, date, time, path, repeat, repeatval);
break;
case HOUR:
time.addHour(repeatval);
//need to check for day overflow
data->db->addBackupJob(desc, date, time, path, repeat, repeatval);
break;
case DAY:
date.addDay(repeatval);
data->db->addBackupJob(desc, date, time, path, repeat, repeatval);
break;
case WEEK:
date.addWeek(repeatval);
data->db->addBackupJob(desc, date, time, path, repeat, repeatval);
break;
case MONTH:
date.addMonth(repeatval);
data->db->addBackupJob(desc, date, time, path, repeat, repeatval);
break;
case YEAR:
date.addMonth(repeatval*12);
data->db->addBackupJob(desc, date, time, path, repeat, repeatval);
break;
default:
break;
}
}
}
}while(ret);
//check restore here... mostly the same.. but no repeats
//restore query
data->queryRestore();
do
{
ret = data->db->getRestoreRow(desc, path, &index);
if(ret)
{
data->msg(NONE, "Restoring: %d %s: %s", index, desc.c_str(), path.c_str());
//do the restore here!
// tar file, path
new fbRestore(data, desc, path);
//remove row
data->db->deleteRow("restore", index);
}
}while(ret);
//sleep 10 seconds
_sleep(10);
}
}