]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/backup/backup.pl
core125: Ship updated backup include
[people/pmueller/ipfire-2.x.git] / config / backup / backup.pl
CommitLineData
cf29614f 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
2b4593b2 5# Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> #
70df8302
MT
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
22require '/var/ipfire/general-functions.pl';
23require "${General::swroot}/lang.pl";
24require "${General::swroot}/header.pl";
e0800c21 25use File::Path;
cf29614f
CS
26my $debug = 1;
27my @include = "";
28my ($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
f31d3c1f 35if (($ARGV[0] eq 'include') || ($ARGV[0] eq 'iso')) {
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);
84578512 49 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten.ipf --exclude-from='/var/ipfire/backup/exclude' --exclude-from='/var/ipfire/backup/exclude.user' --files-from='/tmp/include' --files-from='/var/ipfire/backup/include.user'");
8e8bbd9d 50 system("rm /tmp/include");
f31d3c1f
DG
51 if ($ARGV[0] eq 'iso') {
52 system("/usr/local/bin/backupiso $Jahr$Monat$Monatstag-$Stunden$Minuten &");
53 }
8e8bbd9d 54}
69addbb8 55elsif ($ARGV[0] eq 'exclude') {
cf29614f
CS
56 &createinclude;
57 open(DATEI, ">/tmp/include") || die "Could not save temp include file";
58 print DATEI @include;
59 close(DATEI);
84578512 60 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten.ipf --exclude-from='/var/ipfire/backup/exclude' --exclude-from='/var/ipfire/backup/exclude.user' --files-from='/tmp/include' --files-from='/var/ipfire/backup/include.user'");
cf29614f
CS
61 system("rm /tmp/include");
62}
69addbb8 63elsif ($ARGV[0] eq 'restore') {
c0faa0ef 64 system("cd / && tar -xvz -p -f /tmp/restore.ipf");
c490c6e8
AM
65 #Here some converter scripts to correct old Backups (before core 65)
66 system("/usr/sbin/ovpn-ccd-convert");
a60dbb4b 67 #OUTGOINGFW CONVERTER
9edb1d7a 68 if( -d "${General::swroot}/outgoing"){
6d8eb5de
AM
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";
9edb1d7a 73 }
6d8eb5de
AM
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";
a60dbb4b 78 }
e09884e0
AM
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");
a60dbb4b
AM
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");
a60dbb4b 89 #START CONVERTER "OUTGOINGFW"
99e698d0 90 system("/usr/sbin/convert-outgoingfw");
e09884e0
AM
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"
9edb1d7a 96 rmtree("${General::swroot}/outgoing");
e0800c21 97 }
a60dbb4b 98 #XTACCESS CONVERTER
9edb1d7a 99 if( -d "${General::swroot}/xtaccess"){
6d8eb5de
AM
100 if( -f "${General::swroot}/firewall/input" ){
101 unlink("${General::swroot}/firewall/input");
102 system("touch ${General::swroot}/firewall/input");
a60dbb4b
AM
103 }
104 #START CONVERTER "XTACCESS"
99e698d0 105 system("/usr/sbin/convert-xtaccess");
6d8eb5de 106 chown 99,99,"${General::swroot}/firewall/input";
9edb1d7a 107 rmtree("${General::swroot}/xtaccess");
e0800c21 108 }
a60dbb4b 109 #DMZ-HOLES CONVERTER
6d8eb5de
AM
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");
a60dbb4b
AM
114 }
115 #START CONVERTER "DMZ-HOLES"
116 system("/usr/sbin/convert-dmz");
6d8eb5de 117 chown 99,99,"${General::swroot}/firewall/config";
f7e649dd 118 rmtree("${General::swroot}/dmzholes");
a60dbb4b
AM
119 }
120 #PORTFORWARD CONVERTER
121 if( -d "${General::swroot}/portfw"){
6d8eb5de 122 #START CONVERTER "PORTFW"
cbc62198 123 system("/usr/sbin/convert-portfw");
6d8eb5de 124 rmtree("${General::swroot}/portfw");
a60dbb4b 125 }
8039a710 126 system("/usr/local/bin/firewallctrl");
59cbe386
MT
127
128 # Convert old OpenVPN CCD files (CN change, core 75).
129 system("/usr/local/bin/convert-ovpn");
8e8bbd9d 130}
5ad5a6bc 131elsif ($ARGV[0] eq 'restoreaddon') {
b8e5a9c5 132 if ( -e "/tmp/$ARGV[1]" ){system("mv /tmp/$ARGV[1] /var/ipfire/backup/addons/backup/$ARGV[1]");}
c0faa0ef 133 system("cd / && tar -xvz -p -f /var/ipfire/backup/addons/backup/$ARGV[1]");
5ad5a6bc 134}
69addbb8 135elsif ($ARGV[0] eq 'cli') {
75abe7e9 136 system("tar -cvzf /var/ipfire/backup/$Jahr$Monat$Monatstag-$Stunden$Minuten-$ARGV[1].ipf --files-from='$ARGV[2]' --exclude-from='$ARGV[3]'");
cf29614f 137}
901a50cf
CS
138elsif ($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]'");
140}
a6c19081
MT
141elsif ($ARGV[0] =~ /\.(iso|ipf)$/ ) {
142 unlink("$ARGV[0]");
b90a7e56 143}
69addbb8
CS
144elsif ($ARGV[0] eq '') {
145 printf "No argument given, please use <include><exclude><cli>\n"
8e8bbd9d 146}
a609bfb0 147elsif ($ARGV[0] eq 'makedirs') {
2a1f6aa7
CS
148 system("mkdir -p /var/ipfire/backup/addons");
149 system("mkdir -p /var/ipfire/backup/addons/backup");
150 system("mkdir -p /var/ipfire/backup/addons/includes");
a609bfb0 151}
8e8bbd9d 152
cf29614f
CS
153sub createinclude(){
154
155 open(DATEI, "<${General::swroot}/backup/include") || die "Can not open include file";
156 my @Zeilen = <DATEI>;
157 close(DATEI);
84578512 158
cf29614f 159 foreach (@Zeilen){
5604dc74
AF
160 chomp($_);
161 my @files = `find $_ -maxdepth 0 2>/dev/null`;
cf29614f
CS
162 foreach (@files){
163 push(@include,$_);
5604dc74 164 }
cf29614f
CS
165 }
166}