1 |
rodolico |
1 |
drop table if exists backups_server;
|
|
|
2 |
create table backups_server (
|
|
|
3 |
backups_server_id int unsigned not null auto_increment,
|
|
|
4 |
device_id int unsigned not null references device (device_id),
|
|
|
5 |
backup_space bigint comment 'size in bytes available for backups',
|
|
|
6 |
primary key (backups_server_id)
|
|
|
7 |
) comment 'Just a linking table to available backup servers';
|
|
|
8 |
|
|
|
9 |
drop table if exists backups;
|
|
|
10 |
create table backups (
|
|
|
11 |
backups_id int unsigned not null auto_increment,
|
|
|
12 |
device_id int unsigned not null references device (device_id),
|
|
|
13 |
backups_server_id int unsigned not null references backup_server (backups_server_id),
|
|
|
14 |
allocated_size bigint default 1073741824 comment 'number of bytes client is paying for',
|
|
|
15 |
start_time time comment 'default start time of backup',
|
|
|
16 |
notes text comment 'any notes we want to keep on this',
|
70 |
rodolico |
17 |
bandwidth_allocated int unsigned comment 'amount of bandwidth in megabits/s',
|
1 |
rodolico |
18 |
responsible_party varchar(64) comment 'email address of who to notify for problems',
|
70 |
rodolico |
19 |
added_date date,
|
|
|
20 |
removed_date date default null,
|
1 |
rodolico |
21 |
primary key (backups_id)
|
|
|
22 |
) comment 'stores information on backup jobs allocated';
|
|
|
23 |
|
70 |
rodolico |
24 |
|
|
|
25 |
|
1 |
rodolico |
26 |
DROP TABLE IF EXISTS backups_run;
|
|
|
27 |
CREATE TABLE backups_run (
|
|
|
28 |
backups_run_id int unsigned not null auto_increment,
|
|
|
29 |
backups_id int unsigned not null references backups( backups_id ),
|
|
|
30 |
report_date datetime not null comment 'Date on the actual log file as part of its filename',
|
|
|
31 |
start_time datetime NOT NULL default '0000-00-00 00:00:00' comment 'when job started',
|
|
|
32 |
version varchar(10) comment 'Version of rsbackup creating processing this run',
|
|
|
33 |
end_time datetime NOT NULL default '0000-00-00 00:00:00' comment 'when job ended',
|
|
|
34 |
files_count bigint comment 'total number of files to be checked',
|
|
|
35 |
files_size bigint comment 'size of all files to be checked in bytes',
|
|
|
36 |
transferred_count bigint comment 'number of files transferred',
|
|
|
37 |
transferred_size bigint comment 'size of files transferred in bytes',
|
|
|
38 |
files_deleted bigint comment 'number of files which were deleted',
|
|
|
39 |
data_sent bigint comment 'bytes sent to server',
|
|
|
40 |
data_received bigint comment 'bytes received from server',
|
|
|
41 |
PRIMARY KEY (backups_run_id)
|
|
|
42 |
) comment 'added for each backup that runs';
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
DROP TABLE IF EXISTS backups_usage;
|
|
|
46 |
CREATE TABLE backups_usage (
|
|
|
47 |
backups_usage_id int unsigned not null auto_increment,
|
|
|
48 |
report_date date NOT NULL default '0000-00-00',
|
|
|
49 |
backups_id int unsigned not null references backups (backups_id),
|
|
|
50 |
disk_usage bigint comment 'bytes used on backup server',
|
|
|
51 |
num_files bigint comment 'number of files on backup server',
|
|
|
52 |
num_dirs bigint comment 'number of directories on backup server',
|
|
|
53 |
PRIMARY KEY (backups_usage_id)
|
|
|
54 |
) comment 'periodic reports from backup server itself on space used';
|
|
|
55 |
|
|
|
56 |
insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'Backup', 'modules/backup/', now() );
|
|
|
57 |
|
|
|
58 |
/* Reports */
|
|
|
59 |
insert into report ( name, query, parameters ) values ('Active Backups','select device.name Device,
|
|
|
60 |
backupserver.name Server,
|
|
|
61 |
floor(allocated_size/1024/1024/1024) \"Max Size (G)\",
|
|
|
62 |
concat(round(allocated_size / backup_space * 100), \'%\') \"%\",
|
|
|
63 |
start_time Starts
|
|
|
64 |
from backups join backups_server on backups.backups_server_id = backups_server.backups_server_id
|
|
|
65 |
join device backupserver on backups_server.device_id = backupserver.device_id
|
|
|
66 |
join device on backups.device_id = device.device_id','');
|
|
|
67 |
|
|
|
68 |
insert into report ( name, query, parameters ) values ('Device Backup History','select device.name Device,
|
|
|
69 |
backups_run.start_time Started,
|
|
|
70 |
timediff(backups_run.end_time,backups_run.start_time) Duration,
|
|
|
71 |
lpad(floor((data_sent+data_received) / 1024 / 1024), 10, \' \') \"M Xfer\"
|
|
|
72 |
from backups join backups_run using (backups_id)
|
|
|
73 |
join device using (device_id)
|
|
|
74 |
where device.device_id = <device_id>
|
|
|
75 |
and backups_run.start_time >= <start_date>
|
|
|
76 |
and backups_run.start_time < <end_date>
|
|
|
77 |
order by device.name,backups_run.start_time','device_id++Device++select device_id,device.name from device where device_id in (select device_id from backups) order by device.name++select device.name from device where device_id = <value>
|
|
|
78 |
start_date++Starting Date++++
|
|
|
79 |
end_date++Ending Date++++');
|
|
|
80 |
|
|
|
81 |
insert into report ( name, query, parameters ) values ('Backup Stats','select device.name Device,
|
|
|
82 |
max( timediff(backups_run.end_time,backups_run.start_time) ) Longest,
|
|
|
83 |
min( timediff(backups_run.end_time,backups_run.start_time) ) Shortest,
|
|
|
84 |
avg( TIME_TO_SEC(backups_run.end_time)-TIME_TO_SEC(backups_run.start_time) ) AvgTime,
|
|
|
85 |
lpad(format( max((data_sent+data_received) / 1024 / 1024), 0 ),10,\' \') Largest,
|
|
|
86 |
lpad(format( min((data_sent+data_received) / 1024 / 1024), 0 ),10,\' \') Smallest,
|
|
|
87 |
lpad(format(avg( (data_sent+data_received) / 1024 / 1024), 0 ),10,\' \') AvgXFer,
|
|
|
88 |
count(*) Num,
|
|
|
89 |
stddev((data_sent+data_received)) StdDev,
|
|
|
90 |
var_pop((data_sent+data_received)) Var
|
|
|
91 |
from backups join backups_run using (backups_id)
|
|
|
92 |
join device using (device_id)
|
|
|
93 |
group by device.name','');
|
|
|
94 |
|
|
|
95 |
insert into report ( name, query, parameters ) values ('Monthly Backup Transfer','select device.name Device,
|
|
|
96 |
concat(year(backups_run.start_time), \'-\', lpad(month(backups_run.start_time),2,\'0\')) Period,
|
|
|
97 |
lpad(format(sum(data_sent+data_received)/1024/1024/1024,0),10,\' \') \'Transfer\',
|
|
|
98 |
lpad(format((sum(data_sent+data_received)- (allocated_size * 0.01))/1024/1024/1024,0),10,\' \') \'Overage\'
|
|
|
99 |
from backups join backups_run using (backups_id)
|
|
|
100 |
join device using (device_id)
|
|
|
101 |
where month(backups_run.start_time) = <month> and year(backups_run.start_time) = <year>
|
|
|
102 |
group by device.name, concat(year(backups_run.start_time), \'-\', month(backups_run.start_time))
|
|
|
103 |
order by device.name, concat(year(backups_run.start_time), \'-\', month(backups_run.start_time))','month++Report Month (number)++++
|
|
|
104 |
year++Report Year (4 digit)++++');
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
insert into report ( name, query, parameters ) values ('Client Monthly Transfer History','select device.name Device,
|
|
|
108 |
concat(year(backups_run.start_time), \'-\', lpad(month(backups_run.start_time),2,\'0\')) Period,
|
|
|
109 |
lpad(format(sum(data_sent+data_received)/1024/1024/1024,0),10,\' \') \'Transfer\',
|
|
|
110 |
lpad(format((sum(data_sent+data_received)- (allocated_size * 0.01))/1024/1024/1024,0),10,\' \') \'Overage\'
|
|
|
111 |
from backups join backups_run using (backups_id)
|
|
|
112 |
join device using (device_id)
|
|
|
113 |
where device.device_id = <device_id>
|
|
|
114 |
group by device.name, concat(year(backups_run.start_time), \'-\', month(backups_run.start_time))
|
|
|
115 |
order by device.name, concat(year(backups_run.start_time), \'-\', month(backups_run.start_time))','device_id++Computer++select device_id,device.name from device where device_id in (select device_id from backups) order by device.name++select name from device where device_id = <value>');
|
38 |
rodolico |
116 |
|
|
|
117 |
/* last <count> backups recorded */
|
|
|
118 |
|
50 |
rodolico |
119 |
insert into report ( name, query, parameters ) values ('Backup History','select
|
38 |
rodolico |
120 |
backups_run.start_time Started,
|
|
|
121 |
backups_run.end_time Ended,
|
|
|
122 |
backups_run.version Version,
|
|
|
123 |
format(backups_run.files_count,0) Files,
|
|
|
124 |
format(backups_run.files_size/1024/1024,0) \'Size (M)\',
|
|
|
125 |
format(backups_run.transferred_count,0) Transfer,
|
|
|
126 |
format(backups_run.skipped,0) Skipped,
|
|
|
127 |
format(backups_run.files_deleted,0) Deleted,
|
|
|
128 |
format(backups_run.data_sent/1024/1024,2) \'MB Out\',
|
|
|
129 |
format(backups_run.data_received/1024/1024,2) \'MB In\',
|
|
|
130 |
backups_run.disk_used Disk
|
|
|
131 |
from
|
|
|
132 |
backups_run join backups using (backups_id)
|
|
|
133 |
where
|
|
|
134 |
backups.device_id = <device_id>
|
|
|
135 |
order by
|
|
|
136 |
backups_run.report_date desc
|
|
|
137 |
limit <count>','device_id++Device ID++++
|
50 |
rodolico |
138 |
count++Number of Reports++++');
|
70 |
rodolico |
139 |
|
|
|
140 |
/* This has a menu entry, so add it */
|
|
|
141 |
/* first, make sure we don't have any danglies */
|
|
|
142 |
/* create three menu options. First one is the main menu option (ie, no parent_id) */
|
|
|
143 |
insert into menu( url, caption, parent_id) values ('/modules/backup/', 'Backups', null);
|