-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.pl
executable file
·64 lines (51 loc) · 1.73 KB
/
backup.pl
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
#!/usr/bin/perl
# Nicholas Mossor Rathmann, 2009-2010, All rights reserved.
# Backs up important system and user files.
# Arguments: None.
# Example: backup.pl
use warnings;
use strict;
require '/files/scripts/commonLibrary_header.pl';
require '/files/scripts/commonLibrary_credentials.pl';
my $week = getWeek();
my $year = getYear();
# Determine directories to bacup, this includes:
# system, www, scripts, current user files, and 3 years back.
my @dirs_to_backup = (
"$CL::HOMES_BASE/".($year-3).'-'.($year-2),
"$CL::HOMES_BASE/".($year-2).'-'.($year-1),
"$CL::HOMES_BASE/".($year-1).'-'.($year),
"$CL::HOMES_BASE/".($year). '-'.($year+1),
"$CL::HOMES_BASE/scripts",
"$CL::HOMES_BASE/www",
"$CL::HOMES_BASE/system"
);
# Determine location to back various files up to.
my $dest = "$CL::BACKUP_BASE/week$week";
my $sql = "$dest/mysql_${week}.sql";
my $ldif = "$dest/ldap_${week}.ldif";
# Remove anything at backup destination.
system("/bin/rm -R $dest");
# Make destination directory.
system("/bin/mkdir $dest");
# Copy directories to backup location.
system("/bin/cp -R ".join(' ', @dirs_to_backup)." $dest");
# Create a MySQL dump to the backup location.
system("/usr/bin/mysqldump -u $CL::MYSQL_ROOT -p$CL::MYSQL_ROOTPASSWD --all-databases > $sql");
# Backup all LDAP data to the backup location.
system("/usr/bin/ldapsearch -L -x -w $CL::LDAP_ROOTPASSWD -D '$CL::LDAP_ROOT' -b '$CL::LDAP_BASE_ROOT' > $ldif");
# Ensure file owner only, can read the MySQL and LDAP files.
chmod 0400, $ldif;
chmod 0400, $sql;
sub getWeek {
my $week;
$week = `date +%V`;
chomp($week);
return $week;
}
sub getYear {
my $year;
$year = `date +%Y`;
chomp($year);
return $year;
}