]>
Commit | Line | Data |
---|---|---|
cf29614f | 1 | #!/usr/bin/perl |
70df8302 MT |
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 | ############################################################################### | |
cf29614f CS |
21 | |
22 | require '/var/ipfire/general-functions.pl'; | |
23 | require "${General::swroot}/lang.pl"; | |
24 | require "${General::swroot}/header.pl"; | |
25 | ||
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') { | |
8e8bbd9d | 36 | &createinclude; |
d39a5cb6 CS |
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`; | |
8e8bbd9d CS |
42 | foreach (@files){ |
43 | push(@include,$_); | |
44 | } | |
45 | open(DATEI, ">/tmp/include") || die "Could not save temp include file"; | |
46 | print DATEI @include; | |
d39a5cb6 | 47 | print "/var/log/messages"; |
8e8bbd9d | 48 | close(DATEI); |
69addbb8 | 49 | system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden:$Minuten.ipf --files-from='/tmp/include' --exclude-from='/var/ipfire/backup/exclude'"); |
8e8bbd9d CS |
50 | system("rm /tmp/include"); |
51 | } | |
69addbb8 | 52 | elsif ($ARGV[0] eq 'exclude') { |
cf29614f CS |
53 | &createinclude; |
54 | open(DATEI, ">/tmp/include") || die "Could not save temp include file"; | |
55 | print DATEI @include; | |
56 | close(DATEI); | |
69addbb8 | 57 | system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden:$Minuten.ipf --files-from='/tmp/include' --exclude-from='/var/ipfire/backup/exclude'"); |
cf29614f CS |
58 | system("rm /tmp/include"); |
59 | } | |
69addbb8 | 60 | elsif ($ARGV[0] eq 'restore') { |
a97442ad | 61 | system("cd / && tar -xvz --preserve -f /tmp/restore.ipf"); |
8e8bbd9d | 62 | } |
69addbb8 CS |
63 | elsif ($ARGV[0] eq 'cli') { |
64 | system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden:$Minuten-$ARGV[1].ipf --files-from='$ARGV[2]' --exclude-from='$ARGV[3]'"); | |
cf29614f | 65 | } |
69addbb8 CS |
66 | elsif ($ARGV[0] =~ /ipf$/ ) { |
67 | system("rm /var/ipfire/backup/$ARGV[0]"); | |
8e8bbd9d | 68 | } |
69addbb8 CS |
69 | elsif ($ARGV[0] eq '') { |
70 | printf "No argument given, please use <include><exclude><cli>\n" | |
8e8bbd9d CS |
71 | } |
72 | ||
cf29614f CS |
73 | sub createinclude(){ |
74 | ||
75 | open(DATEI, "<${General::swroot}/backup/include") || die "Can not open include file"; | |
76 | my @Zeilen = <DATEI>; | |
77 | close(DATEI); | |
78 | ||
79 | foreach (@Zeilen){ | |
80 | if ( $_ =~ /\*/){ | |
81 | my @files = `ls $_`; | |
82 | foreach (@files){ | |
83 | push(@include,$_); | |
8e8bbd9d CS |
84 | } |
85 | } | |
cf29614f CS |
86 | else {push(@include,$_);} |
87 | } | |
88 | } |