source: MondoRescue/branches/3.0-mindi-2.1/contrib/backup-kungfu/backup-kungfu

Last change on this file was 541, checked in by bcornec, 18 years ago

Stable is reverted to r436 (2.0.7) to put it in line with 2.0.8 and start from there over

File size: 5.4 KB
Line 
1#!/bin/bash
2#######################################################################
3# This is a script to execute daily/weekly backups over NFS #
4# with mondorescue set of tools made by Hugo Rabson #
5# http://www.mondorescue.com <-- Visit and contribute ! #
6# This script made by Phazeman with a great help of #
7# crash3m @ #mandrake, twkm, Lurch and Speuler @ #bash on #
8# irc.freenode.net. It has been written to make it easy to use on #
9# several machines at the same time. #
10# This product is distributed under the GPL license and is issued #
11# without warrant of anytime against damages, loss of property, or #
12# loss of profita. #
13#######################################################################
14
15# Set the debug level to 1 if you want to print all the params and exit
16# Otherwise set to 0
17
18debug="0"
19
20# Get the date
21date=`date +"%d-%m-%Y"`
22
23function check_conf {
24if [ -f "/etc/backup-kungfu.conf" ]
25then
26 echo -e "\nConfiguration file found. Proceeding...\n"
27 source /etc/backup-kungfu.conf
28else
29 echo -e "\n\033[40m\033[1;31mERROR: No configuration file found ! \nExiting now...\033[0m\n"
30 exit 1
31fi
32}
33
34function check_mondo {
35if [ -x $mondo_path/$mondo_exe ]
36then
37 echo -e "mondoarchive executable found. Proceeding..."
38else
39 echo -e "\033[40m\033[1;31mERROR: mondo_exe variable is set wrong.\nPlease edit the config file and rerun the script.\nExiting now...\033[0m\n"
40 exit 1
41fi
42}
43
44function check_backup_dir {
45 if [ -f $backup_dir ]
46 then
47 echo -e "\033[40m\033[1;31mERROR: backup_dir variable is set wrong.\nPlease edit the config file and rerun the script.\nExiting now...\033[0m\n"
48 exit 1
49 else
50 echo -e "The backup dir found. Proceeding...\n"
51 fi
52}
53
54function check_path {
55 if [ -x $mondo_path/$mondo_exec ]
56 then
57 if [ "$PATH" == "" ]
58 then
59 echo -e "Running as cron job. Exporting path...\n"
60 export PATH=$mondo_path
61 fi
62 else
63 echo -e "\033[40m\033[1;31mERROR: No mondoarchive executable found in $mondo_path/.\nPlease edit the config file and then run again.\nExiting now...\033[0m\n"
64 exit 1
65 fi
66}
67
68function remove_garbage {
69 echo -e "Removing the files left from previous mondoarchive run...\n"
70 rm -rf /root/images
71 rm -rf ${backup_dir}/mondo*
72 rm -rf ${backup_dir}/tmp*
73}
74
75function check_root {
76 if [ "$UID" != "0" ]
77 then
78 echo -e "\n\033[40m\033[1;31mERROR: Root check FAILED (you MUST be root to use this script)! Exiting...\033[0m\n"
79 exit 1
80 fi
81}
82
83function delete_old_backup {
84 answer = "x"
85 while "$(answer)" != ["y" | "Y" | "n" | "N"]
86 do
87 echo -n "Do you want to delete all the previous \
88 backups stored in $(backup_dir)/$(comp_name) ? (y/n) "
89 read answer
90 case "$(answer)" in
91 ["y" | "Y"] )
92 echo -e "Removing the old backup files now...\n"
93 rm -rf ${backup_dir}/${comp_name}*
94 ;;
95 *)
96 ;;
97 esac
98 done
99}
100
101function move_all {
102 # Remove all the previous backups
103 # echo -e "Removing the old backup files now...\n"
104 # rm -rf ${backup_dir}/${comp_name}*
105
106 # Create the new folder and move all the iso and floppy images to it
107 echo -e "Creating the new backup directory and moving the files there...\n"
108 mkdir -p ${backup_dir}/${comp_name}_${date}/images
109 cp /root/images/mindi/* ${backup_dir}/${comp_name}_${date}/images/
110
111 # If you want just move the iso files without renaming them just uncomment the next line
112 # and comment the next for loop
113 mv $backup_dir/*.iso ${backup_dir}/${comp_name}_${date}/
114
115 #for i in `ls $(backup_dir)/*.iso`
116 #do
117 # mv $(backup_dir)/$(i) ${backup_dir}/${comp_name}_${date}/$(comp_name)_backup_$(date)_$i
118 #done
119}
120
121function print_params {
122 echo -e "Debug = $debug\n\
123Mondo executable = $mondo_exe\n\
124Mondo path = $mondo_path\n\
125Backup Dir = $backup_dir\n\
126Excludes = $excludes\n\
127Comp Name = $comp_name\n\
128Mondo Params = $params\n\
129Boot Loader = $bootloader\n\
130Launch from dir = $from_dir\n\
131Date = $date\n\
132Mondo execution = '$archiveit'\n"
133}
134
135function cd_from_dir {
136 if [ -d $from_dir ]
137 then
138 cd $from_dir
139 echo -e "Entering the \"From\" directory...\n"
140 else
141 echo -e "\033[40m\033[1;31mERROR: The from_dir variable is set wrong.\nPlease edit the config file and rerun the script.\nExiting now...\033[0m\n"
142 exit 1
143 fi
144}
145
146function set_exec {
147 archiveit="$mondo_path/${mondo_exe} ${params} -d ${backup_dir} -l ${bootloader} -E '${excludes}' &> /dev/null"
148}
149
150function do_cleanup {
151 remove_garbage;
152 exit 1;
153}
154trap do_cleanup INT
155
156function main {
157if [ $debug == "0" ]
158then # Execute the real backup
159 #Verify if root
160 check_root;
161
162 # Check if mondo_exec set correct
163 check_mondo;
164
165 # Check if the conf file created in /etc
166 check_conf;
167
168 # Check if the backup_dir set correct
169 check_backup_dir;
170
171 # Check mondo_path
172 check_path;
173
174 # Set the execution command
175 set_exec;
176
177 # Remove the garbage from the last run
178 remove_garbage;
179
180 # Enter the big directory to launch the backup
181 cd_from_dir;
182
183 #execute the backup
184 echo -e "Executing the backup now. Please hold on, it can take few howrs.\nLook in /var/log/mondoarchive.log for current status of the backup.\n"
185 eval $archiveit
186
187 # Delete old backups from the dir
188 #delete_old_backup;
189
190 # Copy the mindi images to the backup folder and clean up the mess
191 move_all;
192
193 # Remove all the garbage left afer mondoarchive run
194 remove_garbage;
195else # Print all the params for debug
196 check_root;
197 check_conf;
198 check_path;
199 set_exec;
200 print_params;
201fi
202}
203
204# Execute the main function
205main;
206
Note: See TracBrowser for help on using the repository browser.