]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/backup/backup.pl
b21716185eaad0bdbf653b36ed97b23ff97e9ebb
[people/teissler/ipfire-2.x.git] / config / backup / backup.pl
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 require '/var/ipfire/general-functions.pl';
23 require "${General::swroot}/lang.pl";
24 require "${General::swroot}/header.pl";
25 use File::Path;
26 my $debug = 1;
27 my @include = "";
28 my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);
29 $Jahr = $Jahr + 1900;$Monat = $Monat + 1;
30 $Monat = sprintf("%02d", $Monat);
31 $Monatstag = sprintf("%02d", $Monatstag);
32 $Stunden = sprintf("%02d", $Stunden);
33 $Minuten = sprintf("%02d", $Minuten);
34
35 if (($ARGV[0] eq 'include') || ($ARGV[0] eq 'iso')) {
36 &createinclude;
37 my @files = `find / -name *.log* 2>/dev/null`;
38 foreach (@files){
39 push(@include,$_);
40 }
41 my @files = `find /var/log/ -name *messages* 2>/dev/null`;
42 foreach (@files){
43 push(@include,$_);
44 }
45 open(DATEI, ">/tmp/include") || die "Could not save temp include file";
46 print DATEI @include;
47 print "/var/log/messages";
48 close(DATEI);
49 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten.ipf --files-from='/tmp/include' --exclude-from='/var/ipfire/backup/exclude' --files-from='/var/ipfire/backup/include.user' --exclude-from='/var/ipfire/backup/exclude.user'");
50 system("rm /tmp/include");
51 if ($ARGV[0] eq 'iso') {
52 system("/usr/local/bin/backupiso $Jahr$Monat$Monatstag-$Stunden$Minuten &");
53 }
54 }
55 elsif ($ARGV[0] eq 'exclude') {
56 &createinclude;
57 open(DATEI, ">/tmp/include") || die "Could not save temp include file";
58 print DATEI @include;
59 close(DATEI);
60 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten.ipf --files-from='/tmp/include' --exclude-from='/var/ipfire/backup/exclude' --files-from='/var/ipfire/backup/include.user' --exclude-from='/var/ipfire/backup/exclude.user'");
61 system("rm /tmp/include");
62 }
63 elsif ($ARGV[0] eq 'restore') {
64 system("cd / && tar -xvz -p -f /tmp/restore.ipf");
65 #Here some converter scripts to correct old Backups (before core 65)
66 system("/usr/sbin/ovpn-ccd-convert");
67 if( -d "${General::swroot}/outgoing"){
68 if( -f "${General::swroot}/forward/config" ){
69 unlink("${General::swroot}/forward/config");
70 system("touch ${General::swroot}/forward/config");
71 chown 99,99,"${General::swroot}/forward/config";
72 }
73 if( -f "${General::swroot}/forward/input" ){
74 unlink("${General::swroot}/forward/input");
75 system("touch ${General::swroot}/forward/input");
76 chown 99,99,"${General::swroot}/forward/input";
77 }
78 system("/usr/sbin/convert-outgoingfw");
79 rmtree("${General::swroot}/outgoing");
80 system("/usr/local/bin/forwrdfwctrl");
81 }
82 if( -d "${General::swroot}/xtaccess"){
83 system("/usr/sbin/convert-xtaccess");
84 rmtree("${General::swroot}/xtaccess");
85 }
86 }
87 elsif ($ARGV[0] eq 'restoreaddon') {
88 if ( -e "/tmp/$ARGV[1]" ){system("mv /tmp/$ARGV[1] /var/ipfire/backup/addons/backup/$ARGV[1]");}
89 system("cd / && tar -xvz -p -f /var/ipfire/backup/addons/backup/$ARGV[1]");
90 }
91 elsif ($ARGV[0] eq 'cli') {
92 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten-$ARGV[1].ipf --files-from='$ARGV[2]' --exclude-from='$ARGV[3]'");
93 }
94 elsif ($ARGV[0] eq 'addonbackup') {
95 system("tar -cvzf /var/ipfire/backup/addons/backup/$ARGV[1].ipf --files-from='/var/ipfire/backup/addons/includes/$ARGV[1]'");
96 }
97 elsif ($ARGV[0] =~ /ipf$/ ) {
98 system("rm /var/ipfire/backup/$ARGV[0]");
99 }
100 elsif ($ARGV[0] =~ /iso$/ ) {
101 system("rm /var/tmp/backupiso/$ARGV[0]");
102 }
103 elsif ($ARGV[0] eq '') {
104 printf "No argument given, please use <include><exclude><cli>\n"
105 }
106 elsif ($ARGV[0] eq 'makedirs') {
107 system("mkdir -p /var/ipfire/backup/addons");
108 system("mkdir -p /var/ipfire/backup/addons/backup");
109 system("mkdir -p /var/ipfire/backup/addons/includes");
110 }
111
112 sub createinclude(){
113
114 open(DATEI, "<${General::swroot}/backup/include") || die "Can not open include file";
115 my @Zeilen = <DATEI>;
116 close(DATEI);
117
118 foreach (@Zeilen){
119 if ( $_ =~ /\*/){
120 my @files = `ls $_`;
121 foreach (@files){
122 push(@include,$_);
123 }
124 }
125 else {push(@include,$_);}
126 }
127 }