]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/backup/backup.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
22 require '/var/ipfire/general-functions.pl';
23 require "${General::swroot}/lang.pl";
24 require "${General::swroot}/header.pl";
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);
35 if (($ARGV[0] eq 'include') || ($ARGV[0] eq 'iso')) {
37 my @files = `find / -name *.log* 2>/dev/null`;
41 my @files = `find /var/log/ -name *messages* 2>/dev/null`;
45 open(DATEI
, ">/tmp/include") || die "Could not save temp include file";
47 print "/var/log/messages";
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 &");
55 elsif ($ARGV[0] eq 'exclude') {
57 open(DATEI
, ">/tmp/include") || die "Could not save temp include file";
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");
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");
68 if( -d
"${General::swroot}/outgoing"){
69 if( -f
"${General::swroot}/firewall/config" ){
70 unlink("${General::swroot}/firewall/config");
71 system("touch ${General::swroot}/firewall/config");
72 chown 99,99,"${General::swroot}/firewall/config";
74 if( -f
"${General::swroot}/firewall/outgoing" ){
75 unlink("${General::swroot}/firewall/outgoing");
76 system("touch ${General::swroot}/firewall/outgoing");
77 chown 99,99,"${General::swroot}/firewall/outgoing";
79 unlink("${General::swroot}/fwhosts/customgroups");
80 unlink("${General::swroot}/fwhosts/customhosts");
81 unlink("${General::swroot}/fwhosts/customgroups");
82 unlink("${General::swroot}/fwhosts/customnetworks");
83 unlink("${General::swroot}/fwhosts/customservicegrp");
84 unlink("${General::swroot}/fwhosts/customnetworks");
85 system("touch ${General::swroot}/fwhosts/customgroups");
86 system("touch ${General::swroot}/fwhosts/customhosts");
87 system("touch ${General::swroot}/fwhosts/customnetworks");
88 system("touch ${General::swroot}/fwhosts/customservicegrp");
89 #START CONVERTER "OUTGOINGFW"
90 system("/usr/sbin/convert-outgoingfw");
91 chown 99,99,"${General::swroot}/fwhosts/customgroups";
92 chown 99,99,"${General::swroot}/fwhosts/customhosts";
93 chown 99,99,"${General::swroot}/fwhosts/customnetworks";
94 chown 99,99,"${General::swroot}/fwhosts/customservicegrp";
95 #START CONVERTER "OUTGOINGFW"
96 rmtree
("${General::swroot}/outgoing");
99 if( -d
"${General::swroot}/xtaccess"){
100 if( -f
"${General::swroot}/firewall/input" ){
101 unlink("${General::swroot}/firewall/input");
102 system("touch ${General::swroot}/firewall/input");
104 #START CONVERTER "XTACCESS"
105 system("/usr/sbin/convert-xtaccess");
106 chown 99,99,"${General::swroot}/firewall/input";
107 rmtree
("${General::swroot}/xtaccess");
110 if( -d
"${General::swroot}/dmzholes" || -d
"${General::swroot}/portfw"){
111 if( -f
"${General::swroot}/firewall/config" ){
112 unlink("${General::swroot}/firewall/config");
113 system("touch ${General::swroot}/firewall/config");
115 #START CONVERTER "DMZ-HOLES"
116 system("/usr/sbin/convert-dmz");
117 chown 99,99,"${General::swroot}/firewall/config";
118 rmtree
("${General::swroot}/dmzholes");
120 #PORTFORWARD CONVERTER
121 if( -d
"${General::swroot}/portfw"){
122 #START CONVERTER "PORTFW"
123 system("/usr/sbin/convert-portfw");
124 rmtree
("${General::swroot}/portfw");
126 system("/usr/local/bin/firewallctrl");
128 # Convert old OpenVPN CCD files (CN change, core 75).
129 system("/usr/local/bin/convert-ovpn");
131 elsif ($ARGV[0] eq 'restoreaddon') {
132 if ( -e
"/tmp/$ARGV[1]" ){system("mv /tmp/$ARGV[1] /var/ipfire/backup/addons/backup/$ARGV[1]");}
133 system("cd / && tar -xvz -p -f /var/ipfire/backup/addons/backup/$ARGV[1]");
135 elsif ($ARGV[0] eq 'cli') {
136 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten-$ARGV[1].ipf --files-from='$ARGV[2]' --exclude-from='$ARGV[3]'");
138 elsif ($ARGV[0] eq 'addonbackup') {
139 system("tar -cvzf /var/ipfire/backup/addons/backup/$ARGV[1].ipf --files-from='/var/ipfire/backup/addons/includes/$ARGV[1]'");
141 elsif ($ARGV[0] =~ /ipf$/ ) {
142 system("rm /var/ipfire/backup/$ARGV[0]");
144 elsif ($ARGV[0] =~ /iso$/ ) {
145 system("rm /var/tmp/backupiso/$ARGV[0]");
147 elsif ($ARGV[0] eq '') {
148 printf "No argument given, please use <include><exclude><cli>\n"
150 elsif ($ARGV[0] eq 'makedirs') {
151 system("mkdir -p /var/ipfire/backup/addons");
152 system("mkdir -p /var/ipfire/backup/addons/backup");
153 system("mkdir -p /var/ipfire/backup/addons/includes");
158 open(DATEI
, "<${General::swroot}/backup/include") || die "Can not open include file";
159 my @Zeilen = <DATEI
>;
164 my @files = `find $_ -maxdepth 0 2>/dev/null`;