- Timestamp:
- Jan 11, 2006, 2:20:38 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mindi/analyze-my-lvm
r276 r300 36 36 37 37 Die() { 38 39 38 echo "$1" >> /dev/stderr 39 exit 1 40 40 } 41 41 … … 43 43 44 44 GetValueFromField() { 45 46 45 local res 46 sed s/' '/~/ "$1" | tr -s ' ' ' ' | sed s/'~ '/'~'/ | grep -i "$2~" | cut -d'~' -f2,3,4,5 | tr '~' ' ' | gawk '{ if ($2=="MB") {printf "%sm",$1;} else if ($2=="KB") {printf "%sk",$1;} else if ($2=="GB") {printf "%sg",$1;} else {print $0;};}' 47 47 } 48 48 49 49 50 50 GetLastBit() { 51 52 53 54 55 i=$(($i-1))56 res=`echo "$1" | cut -d'/' -f$i`57 58 51 local i res 52 i=20 53 res="" 54 while [ ! "$res" ] ; do 55 i=$(($i-1)) 56 res=`echo "$1" | cut -d'/' -f$i` 57 done 58 echo "$res" 59 59 } 60 60 61 61 62 62 ProcessLogicalVolume() { 63 local LV_full_string fname logical_volume volume_group device 64 LV_full_string=$1 65 [ ! -e "$1" ] && Die "Cannot find LV file $1" 66 volume_group=`echo "$LV_full_string" | cut -d'/' -f3` 67 logical_volume=`echo "$LV_full_string" | cut -d'/' -f4` 68 if [ $lvmversion = 2 ]; then 69 device=$LV_full_string 70 params=`GenerateLvcreateParameters $device` 71 echo "# lvm lvcreate$params -n $logical_volume $volume_group" 72 else 73 fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume 74 if [ ! -e "$fname" ] ; then 75 echo "Warning - cannot find $volume_group's $logical_volume LV file" 76 else 77 device=`GetValueFromField $fname "name:"` 78 params=`GenerateLvcreateParameters $device` 79 echo "# lvcreate$params -n $logical_volume $volume_group" 80 fi 81 fi 63 local LV_full_string fname logical_volume volume_group device 64 LV_full_string=$1 65 [ ! -e "$1" ] && Die "Cannot find LV file $1" 66 volume_group=`echo "$LV_full_string" | cut -d'/' -f3` 67 logical_volume=`echo "$LV_full_string" | cut -d'/' -f4` 68 if [ $lvmversion = 2 ]; then 69 device=$LV_full_string 70 params=`GenerateLvcreateParameters $device` 71 else 72 fname=/proc/lvm/VGs/$volume_group/LVs/$logical_volume 73 if [ ! -e "$fname" ] ; then 74 echo "Warning - cannot find $volume_group's $logical_volume LV file" 75 else 76 device=`GetValueFromField $fname "name:"` 77 params=`GenerateLvcreateParameters $device` 78 fi 79 fi 80 echo "# $LVMCMD lvcreate$params -n $logical_volume $volume_group" 82 81 } 83 82 84 83 85 84 GenerateLvcreateParameters() { 86 local device stripes stripesize device fname allocation output readahead 87 fname=/tmp/PLF.$$.txt 88 device=$1 89 output="" 90 if [ $lvmversion = 2 ]; then 91 lvm lvdisplay $device > $fname 92 else 93 lvdisplay $device > $fname 94 fi 95 stripes=`GetValueFromField $fname "Stripes"` 96 stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m 97 [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k 98 [ "$stripesize" = "k" ] && stripesize="" 99 allocation=`GetValueFromField $fname "LV Size"` 100 [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m 101 if echo "$allocation" | grep -x ".*g" > /dev/null 2> /dev/null ; then 102 val=`echo "$allocation" | sed s/g//` 103 allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m 104 fi 105 readahead=`GetValueFromField $fname "Read ahead sectors"` 106 rm -f $fname 107 [ "$stripes" ] && output="$output -i $stripes" 108 [ "$stripesize" ] && output="$output -I $stripesize" 109 [ "$allocation" ] && output="$output -L $allocation" 110 [ "$readahead" ] && output="$output -r $readahead" 111 echo "$output" 85 local device stripes stripesize device fname allocation output readahead 86 fname=/tmp/PLF.$$.txt 87 device=$1 88 output="" 89 $LVMCMD lvdisplay $device > $fname 90 stripes=`GetValueFromField $fname "Stripes"` 91 stripesize=`GetValueFromField $fname "Stripe size (MByte)"`m 92 [ "$stripesize" = "m" ] && stripesize=`GetValueFromField $fname "Stripe size (KByte)"`k 93 [ "$stripesize" = "k" ] && stripesize="" 94 allocation=`GetValueFromField $fname "LV Size"` 95 [ ! "`echo "$allocation" | grep "[k,m,g]"`" ] && allocation="$allocation"m 96 if echo "$allocation" | grep -x ".*g" > /dev/null 2> /dev/null ; then 97 val=`echo "$allocation" | sed s/g//` 98 allocation=`echo "$val" | awk '{c=$1; printf "%d", c*1024;}'`m 99 fi 100 readahead=`GetValueFromField $fname "Read ahead sectors"` 101 rm -f $fname 102 [ "$stripes" ] && output="$output -i $stripes" 103 [ "$stripesize" ] && output="$output -I $stripesize" 104 [ "$allocation" ] && output="$output -L $allocation" 105 [ "$readahead" ] && output="$output -r $readahead" 106 echo "$output" 112 107 } 113 108 … … 115 110 116 111 GenerateVgcreateParameters() { 117 local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines 118 current_VG=$1 119 VG_info_file=/tmp/$$.vg-info.txt 120 if [ $lvmversion = 2 ]; then 121 lvm vgdisplay $current_VG > $VG_info_file 122 else 123 vgdisplay $current_VG > $VG_info_file 124 fi 125 max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"` 126 [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255 127 max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"` 128 [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255 129 physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"` 130 output="" 131 [ "$max_logical_volumes" ] && output="$output -l $max_logical_volumes" 132 [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes" 133 [ "$physical_extent_size" ] && output="$output -s $physical_extent_size" 134 echo "$output" 135 rm -f $VG_info_file 112 local current_VG device fname incoming VG_info_file max_logical_volumes max_physical_volumes physical_extent_size output blanklines 113 current_VG=$1 114 VG_info_file=/tmp/$$.vg-info.txt 115 $LVMCMD vgdisplay $current_VG > $VG_info_file 116 max_logical_volumes=`GetValueFromField "$VG_info_file" "MAX LV"` 117 [ $max_logical_volumes -ge 256 ] && max_logical_volumes=255 118 max_physical_volumes=`GetValueFromField "$VG_info_file" "MAX PV"` 119 [ $max_physical_volumes -ge 256 ] && max_physical_volumes=255 120 physical_extent_size=`GetValueFromField "$VG_info_file" "PE Size"` 121 output="" 122 [ "$max_logical_volumes" ] && output="$output -l $max_logical_volumes" 123 [ "$max_physical_volumes" ] && output="$output -p $max_physical_volumes" 124 [ "$physical_extent_size" ] && output="$output -s $physical_extent_size" 125 echo "$output" 126 rm -f $VG_info_file 136 127 } 137 128 … … 141 132 142 133 ProcessVolumeGroup() { 143 local current_VG physical_volumes i list_of_devices VG_params 144 current_VG=$1 145 if [ $lvmversion = 2 ]; then 146 VG_params=`GenerateVgcreateParameters $current_VG` 147 list_of_devices=`lvm pvs | grep "$current_VG" | awk '{print $1}'` 148 echo "# lvm vgcreate $current_VG$VG_params $list_of_devices" 149 echo "# lvm vgchange -a y $current_VG" 150 else 151 info_file=/proc/lvm/VGs/$current_VG/group 152 physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs` 153 VG_params=`GenerateVgcreateParameters $current_VG` 154 list_of_devices="" 155 for i in $physical_volumes ; do 156 fname=/proc/lvm/VGs/$current_VG/PVs/$i 157 device=`GetValueFromField $fname "name:"` 158 list_of_devices="$list_of_devices $device" 159 done 160 echo "# vgcreate $current_VG$VG_params$list_of_devices" 161 echo "# vgchange -a y $current_VG" 162 fi 134 local current_VG physical_volumes i list_of_devices VG_params 135 current_VG=$1 136 if [ $lvmversion = 2 ]; then 137 VG_params=`GenerateVgcreateParameters $current_VG` 138 list_of_devices=`$LVMCMD pvs | grep "$current_VG" | awk '{print $1}'` 139 else 140 info_file=/proc/lvm/VGs/$current_VG/group 141 physical_volumes=`ls /proc/lvm/VGs/$current_VG/PVs` 142 VG_params=`GenerateVgcreateParameters $current_VG` 143 list_of_devices="" 144 for i in $physical_volumes ; do 145 fname=/proc/lvm/VGs/$current_VG/PVs/$i 146 device=`GetValueFromField $fname "name:"` 147 list_of_devices="$list_of_devices $device" 148 done 149 fi 150 echo "# $LVMCMD vgcreate $current_VG$VG_params $list_of_devices" 151 echo "# $LVMCMD vgchange -a y $current_VG" 163 152 } 164 153 … … 166 155 167 156 ListAllPhysicalVolumes() { 168 169 lvmpvscan 2> /dev/null | grep 'PV' | awk '{print $2}'170 171 pvscan 2> /dev/null | grep '"' | cut -d'"' -f2172 157 if [ $lvmversion = 2 ]; then 158 $LVMCMD pvscan 2> /dev/null | grep 'PV' | awk '{print $2}' 159 else 160 pvscan 2> /dev/null | grep '"' | cut -d'"' -f2 161 fi 173 162 } 174 163 175 164 176 165 ListAllVolumeGroups() { 177 if [ $lvmversion = 2 ]; then 178 lvm vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}' 179 else 180 vgdisplay 2> /dev/null | awk '/^VG Name/ {print $3;}' 181 fi 166 $LVMCMD vgdisplay 2> /dev/null | awk '/^ *VG Name/ {print $3;}' 182 167 } 183 168 184 169 185 170 ListLvmDrivesAndPartitions() { 186 if [ $lvmversion = 2 ]; then 187 lvm vgdisplay -v |grep "PV Name" | awk '{print $3}' 188 else 189 vgdisplay -v |grep "PV Name" | awk '{print $4}' 190 fi 171 $LVMCMD vgdisplay -v |grep "PV Name" | awk '{print $3}' 191 172 } 192 173 … … 194 175 195 176 PrettifyList() { 196 197 198 199 echo -en "$i "200 201 177 local i 178 echo -en "$1" 179 for i in $2 ; do 180 echo -en "$i " 181 done 182 echo "" 202 183 } 203 184 204 185 205 186 ListAllLogicalVolumes() { 206 207 lvmlvscan | grep "'" | cut -d"'" -f2208 209 lvscan | grep '"' | cut -d'"' -f2210 187 if [ $lvmversion = 2 ]; then 188 $LVMCMD lvscan | grep "'" | cut -d"'" -f2 189 else 190 lvscan | grep '"' | cut -d'"' -f2 191 fi 211 192 } 212 193 … … 214 195 215 196 WriteShutdownScript() { 216 local i 217 echo "" 218 echo "Finally, to shut down and delete the volumes, do this:-" 219 if [ $lvmversion = 2 ]; then 197 local i 198 echo "" 199 echo "Finally, to shut down and delete the volumes, do this:-" 220 200 for i in `ListAllLogicalVolumes` ; do 221 echo "( lvmlvremove -f $i)"201 echo "($LVMCMD lvremove -f $i)" 222 202 done 223 203 for i in `ListAllVolumeGroups` ; do 224 echo "( lvmvgchange -a n $i)"204 echo "($LVMCMD vgchange -a n $i)" 225 205 done 226 206 for i in `ListAllVolumeGroups` ; do 227 echo "(lvm vgremove $i)" 228 done 229 echo "(rmmod dm-mod & rmmod dm_mod & )" 230 else 231 for i in `ListAllLogicalVolumes` ; do 232 echo "(lvremove -f $i)" 233 done 234 for i in `ListAllVolumeGroups` ; do 235 echo "(vgchange -a n $i)" 236 done 237 for i in `ListAllVolumeGroups` ; do 238 echo "(vgremove $i)" 239 done 240 echo "(rmmod lvm-mod)" 241 fi 207 echo "($LVMCMD vgremove $i)" 208 done 209 if [ $lvmversion = 2 ]; then 210 echo "(rmmod dm-mod & rmmod dm_mod & )" 211 else 212 echo "(rmmod lvm-mod)" 213 fi 242 214 } 243 215 … … 247 219 which lvmdiskscan 2>/dev/null 2>&1 || Die "Cannot find lvmdiskscan. Are you sure you're using LVM?" 248 220 if [ -e "/proc/lvm/global" ] && [ "`tr -s '\t' ' ' < /proc/lvm/global | grep "0 VGs 0 PVs 0 LVs"`" != "" ] ; then 249 exit 0 250 fi 251 252 # Sq-Mod ... V1 has different output. --version is not legal but version 253 # gets displayed so I guess it's ok... This should work for both. 254 255 #lvmversion=`lvmdiskscan --version | grep "LVM version:" | cut -d: -f2 | cut -d. -f1 | sed -e 's/ //g'` 256 257 lvmversion=`lvmdiskscan --help | 221 exit 0 222 fi 223 224 lvmversion=`lvmdiskscan --help 2>&1 | 258 225 grep -E "Logical Volume Manager|LVM version:" | 259 226 cut -d: -f2 | cut -d. -f1 | … … 262 229 263 230 if which lvm 2>/dev/null; then 264 version=`lvm version | grep "LVM version" | awk '{print $3}'` 265 i="`echo "$version" | cut -d'.' -f1`" 266 echo "i=$i" 267 if [ "$i" -ge "2" ] ; then 268 # if [ $version >= "2.00" ]; then 269 lvmversion=2 270 fi 231 version=`lvm version | grep "LVM version" | awk '{print $3}'` 232 i="`echo "$version" | cut -d'.' -f1`" 233 echo "i=$i" 234 if [ "$i" -ge "2" ] ; then 235 lvmversion=2 236 fi 271 237 fi 272 238 273 239 if [ $lvmversion = 2 ]; then 274 echo "LVM version >= 2.0 found." 240 echo "LVM version >= 2.0 found." 241 LVMCMD="lvm" 242 else 243 LVMCMD="" 275 244 fi 276 245 … … 281 250 echo "To get started, type:-" 282 251 if [ $lvmversion = 2 ]; then 283 echo "(insmod dm-mod)" 284 echo "(insmod dm_mod)" 285 echo "# lvm vgchange -an" 252 echo "(insmod dm-mod)" 253 echo "(insmod dm_mod)" 286 254 else 287 288 echo "# vgchange -an" 289 fi 255 echo "(insmod lvm-mod)" 256 fi 257 echo "# $LVMCMD vgchange -an" 290 258 for i in `ListAllPhysicalVolumes` ; do 291 # echo "# dd if=/dev/zero of=$i bs=512 count=1" 292 if [ $lvmversion = 2 ]; then 293 echo "# echo y | lvm pvcreate -ff $i" 294 else 295 echo "# echo y | pvcreate -ff $i" 296 fi 297 done 298 if [ $lvmversion = 2 ]; then 299 echo "# lvm vgscan; echo" 300 else 301 echo "# vgscan; echo" 302 fi 259 echo "# echo y | $LVMCMD pvcreate -ff $i" 260 done 261 echo "# $LVMCMD vgscan; echo" 303 262 echo "" 304 263 echo "Create and activate the VG's (volume groups)." 305 264 all_volume_groups=`ListAllVolumeGroups` 306 265 for current_VG in $all_volume_groups ; do 307 308 309 310 266 if [ $lvmversion -ne 2 ]; then 267 echo "# rm -Rf /dev/$current_VG" 268 fi 269 ProcessVolumeGroup $current_VG 311 270 done 312 271 echo "" … … 314 273 all_logical_volumes=`ListAllLogicalVolumes` 315 274 for current_LV in $all_logical_volumes ; do 316 275 ProcessLogicalVolume $current_LV 317 276 done 318 277 echo "" 319 if [ $lvmversion = 2 ]; then 320 echo "# lvm vgscan" 321 else 322 echo "# vgscan" 323 fi 278 echo "# $LVMCMD vgscan" 324 279 echo "Now you may format the LV's:-" 325 280 for i in `ListAllLogicalVolumes` ; do 326 281 echo "(mkfs -t foo $i or something like that)" 327 282 done 328 283 WriteShutdownScript -
trunk/mindi/mindi
r292 r300 1025 1025 local module_list module fname oss r kern 1026 1026 oss="/root/oss/modules" 1027 module_list= `ListKernelModules`1027 module_list="`lsmod | sed -n '2,$s/ .*//p'`" 1028 1028 ### 1029 1029 ### Sq-Modification ... Use kernelname for module search path if specified … … 1032 1032 if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ] 1033 1033 then 1034 1035 else 1036 1034 kern=${kernelname} 1035 else 1036 kern="`uname -r`" 1037 1037 fi 1038 1038 ### … … 1041 1041 for module in $module_list $EXTRA_MODS ; do 1042 1042 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1` 1043 echo "module $module --> $r" >> $LOGFILE1044 [ "$r" ] && echo "$r"1045 [ -f "$oss" ] && find $oss | fgrep $module1043 echo "module $module --> $r" >> $LOGFILE 1044 [ "$r" ] && echo "$r" 1045 [ -f "$oss" ] && find $oss | fgrep $module 1046 1046 done 1047 1047 find /lib/modules/$kern/modules.* -type f 2> /dev/null … … 1051 1051 1052 1052 1053 ListKernelModules() {1054 local output q1055 output=""1056 for q in `lsmod | sed -n '2,$s/ .*//p'` ; do1057 output="$q $output"1058 done1059 echo "$output"1060 }1053 #ListKernelModules() { 1054 #local output q 1055 #output="" 1056 #for q in `lsmod | sed -n '2,$s/ .*//p'` ; do 1057 #output="$q $output" 1058 #done 1059 #echo "`lsmod | sed -n '2,$s/ .*//p'`" 1060 #} 1061 1061 1062 1062 … … 1235 1235 1236 1236 echo -en "for outerloop in 1 2 3 4 5 ; do\necho -en \".\"\n" >> $outfile 1237 list_to_echo="` ListKernelModules`"1237 list_to_echo="`lsmod | sed -n '2,$s/ .*//p'`" 1238 1238 # LTE=`echo "$list_to_echo" | tr ' ' '\n' | grep -n "" | cut -d':' -f2,3,4 | tr '\n' ' '` 1239 1239 # lte_old="$LTE" … … 1245 1245 # Make temporary modprobe.conf file if we are told so 1246 1246 if [ $tmpmodprobe_flag == "Y" ] ; then 1247 infile="/tmp/modprobe.conf.mindi.$$"1248 find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f > $infile1249 else 1250 infile="/etc/modules.conf"1247 infile="/tmp/modprobe.conf.mindi.$$" 1248 find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f > $infile 1249 else 1250 infile="/etc/modules.conf" 1251 1251 fi 1252 1252 for module in $list_to_echo $EXTRA_MODS ; do 1253 params=`sed -n "s/^options \\+$module \\+//p" $infile`1254 modpaths=`FindSpecificModuleInPath $searchpath $module`1255 for i in $modpaths ; do1256 echo "MyInsmod $i $params > /dev/null 2> /dev/null" \1257 | tr '.' '#' \1258 | sed s/#o#gz/#o/ \1259 | sed s/#o#gz/#o/ \1260 | sed s/#ko#gz/#ko/ \1261 | sed s/#ko#gz/#ko/ \1253 params=`sed -n "s/^options \\+$module \\+//p" $infile` 1254 modpaths=`FindSpecificModuleInPath $searchpath $module` 1255 for i in $modpaths ; do 1256 echo "MyInsmod $i $params > /dev/null 2> /dev/null" \ 1257 | tr '.' '#' \ 1258 | sed s/#o#gz/#o/ \ 1259 | sed s/#o#gz/#o/ \ 1260 | sed s/#ko#gz/#ko/ \ 1261 | sed s/#ko#gz/#ko/ \ 1262 1262 | tr '#' '.' >> $outfile 1263 1264 echo -en "$i added to module list.\n" >> $LOGFILE 1265 done 1263 echo -en "$i added to module list.\n" >> $LOGFILE 1264 done 1266 1265 done 1267 1266 echo -en "done\n" >> $outfile … … 1272 1271 # Remove temporary modprobe.conf file if we have created one 1273 1272 if [ $tmpmodprobe_flag == "Y" ] ; then 1274 rm -f $infile1273 rm -f $infile 1275 1274 fi 1276 1275 } … … 2870 2869 2871 2870 2872 2873 ListUnsavedKernelModules() { 2874 local fname modules 2875 fname=/tmp/$RANDOM.$$.$RANDOM 2876 ListKernelModules > $fname2877 lsmod | cut -d' ' -f1 >> $fname2878 lsmod | cut -d' ' -f1 >> $fname2879 modules=`sort $fname | uniq -d2 | tr '\n' ' '`2880 rm -f $fname2881 [ "$modules" ] && echo "Unsaved kernel modules: $modules" >> $LOGFILE2882 }2871 # BERLIOS: This function is wrong 2872 # Should be recoded. Desactivated in between 2873 2874 #ListUnsavedKernelModules() { 2875 #local fname modules 2876 #fname=/tmp/$RANDOM.$$.$RANDOM 2877 #lsmod | sed -n '2,$s/ .*//p' > $fname 2878 #modules=`sort $fname | uniq -d2 | tr '\n' ' '` 2879 #rm -f $fname 2880 #[ "$modules" ] && echo "Unsaved kernel modules: $modules" >> $LOGFILE 2881 #} 2883 2882 2884 2883 … … 3242 3241 rm -f /tmp/mountlist.txt.$$ $FDISKLOG /tmp/mindilinux 3243 3242 LogIt "$FRIENDLY_OUTSTRING\n" 3244 ListUnsavedKernelModules3243 #ListUnsavedKernelModules 3245 3244 for mtpt in $FLOPPY_WAS_MOUNTED ; do 3246 3245 mount $mtpt -
trunk/mondo/ChangeLog
r295 r300 18 18 - Abort|Warn when one of the include|exclude dirs (-I|-E) does not exist 19 19 (Bruno Cornec/Jeffs) 20 - Replaced partimagehack with ntfsclone from ntfsprogs package. 21 (Andree Leidenfrost) 20 22 21 23 v2.06 (2005-12-23) -
trunk/mondo/mondo/common/libmondo-archive-EXT.h
r262 r300 27 27 extern int slice_up_file_etc(struct s_bkpinfo *bkpinfo, 28 28 char *biggie_filename, 29 char * partimagehack_fifo,29 char *ntfsprog_fifo, 30 30 long biggie_file_number, 31 31 long noof_biggie_files, 32 bool use_ partimagehack);32 bool use_ntfsprog); 33 33 extern int verify_data(struct s_bkpinfo *bkpinfo); 34 34 extern void wipe_archives(char *d); -
trunk/mondo/mondo/common/libmondo-archive.c
r262 r300 1968 1968 char *bigfile_fname = NULL; 1969 1969 char *sz_devfile; 1970 char * partimagehack_fifo = NULL;1970 char *ntfsprog_fifo = NULL; 1971 1971 /*@ long *********************************************** */ 1972 1972 long biggie_file_number = 0; … … 1981 1981 FILE *ftmp = NULL; 1982 1982 bool delete_when_done; 1983 bool use_ partimagehack;1983 bool use_ntfsprog; 1984 1984 /*@ long long ****************************************** */ 1985 1985 long long biggie_fsize; … … 2015 2015 for (getline(&bigfile_fname, &n, fin); !feof(fin); 2016 2016 getline(&bigfile_fname, &n, fin), biggie_file_number++) { 2017 use_ partimagehack= FALSE;2017 use_ntfsprog = FALSE; 2018 2018 if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) { 2019 2019 bigfile_fname[strlen(bigfile_fname) - 1] = '\0'; … … 2029 2029 delete_when_done = TRUE; 2030 2030 } else { 2031 // Call partimagehackif it's a /dev entry (i.e. a partition to be imaged)2031 // Call ntfsclone (formerly partimagehack) if it's a /dev entry (i.e. a partition to be imaged) 2032 2032 log_msg(2, "bigfile_fname = %s", bigfile_fname); 2033 use_ partimagehack= FALSE;2033 use_ntfsprog = FALSE; 2034 2034 if (!strncmp(bigfile_fname, "/dev/", 5) 2035 2035 && is_dev_an_NTFS_dev(bigfile_fname)) { 2036 use_ partimagehack= TRUE;2036 use_ntfsprog = TRUE; 2037 2037 log_msg(2, 2038 "Calling partimagehackin background because %s is an NTFS partition",2038 "Calling ntfsclone in background because %s is an NTFS partition", 2039 2039 bigfile_fname); 2040 2040 asprintf(&sz_devfile, "/tmp/%d.%d.000", … … 2042 2042 (int) (random() % 32768)); 2043 2043 mkfifo(sz_devfile, 0x770); 2044 partimagehack_fifo = sz_devfile;2044 ntfsprog_fifo = sz_devfile; 2045 2045 switch (pid = fork()) { 2046 2046 case -1: … … 2048 2048 case 0: 2049 2049 log_msg(2, 2050 "CHILD - fip - calling feed_into_ partimage(%s, %s)",2050 "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", 2051 2051 bigfile_fname, sz_devfile); 2052 res = feed_into_ partimage(bigfile_fname, sz_devfile);2052 res = feed_into_ntfsprog(bigfile_fname, sz_devfile); 2053 2053 exit(res); 2054 2054 break; 2055 2055 default: 2056 2056 log_msg(2, 2057 "feed_into_ partimage() called in background --- pid=%ld",2057 "feed_into_ntfsprog() called in background --- pid=%ld", 2058 2058 (long int) (pid)); 2059 2059 … … 2063 2063 // Otherwise, use good old 'dd' and 'bzip2' 2064 2064 else { 2065 partimagehack_fifo = NULL;2065 ntfsprog_fifo = NULL; 2066 2066 } 2067 2067 … … 2072 2072 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2073 2073 write_header_block_to_stream(biggie_fsize, bigfile_fname, 2074 use_ partimagehack?2074 use_ntfsprog ? 2075 2075 BLK_START_A_PIHBIGGIE : 2076 2076 BLK_START_A_NORMBIGGIE); 2077 2077 } 2078 res = slice_up_file_etc(bkpinfo, bigfile_fname, 2079 partimagehack_fifo, biggie_file_number, 2080 noof_biggie_files, use_partimagehack); 2078 res = 2079 slice_up_file_etc(bkpinfo, bigfile_fname, 2080 ntfsprog_fifo, biggie_file_number, 2081 noof_biggie_files, use_ntfsprog); 2081 2082 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2082 2083 tmp = calc_checksum_of_file(bigfile_fname); … … 2996 2997 * 2997 2998 * @param biggie_filename The file to chop up. 2998 * @param partimagehack_fifo The FIFO to partimagehackif this is an imagedev, NULL otherwise.2999 * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise. 2999 3000 * @param biggie_file_number The sequence number of this biggie file (starting from 0). 3000 3001 * @param noof_biggie_files The number of biggie files there are total. … … 3005 3006 int 3006 3007 slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename, 3007 char * partimagehack_fifo, long biggie_file_number,3008 long noof_biggie_files, bool use_ partimagehack)3008 char *ntfsprog_fifo, long biggie_file_number, 3009 long noof_biggie_files, bool use_ntfsprog) 3009 3010 { 3010 3011 … … 3049 3050 3050 3051 biggiestruct.for_backward_compatibility = '\n'; 3051 biggiestruct.use_ partimagehack = use_partimagehack;3052 biggiestruct.use_ntfsprog = use_ntfsprog; 3052 3053 optimal_set_size = bkpinfo->optimal_set_size; 3053 3054 if (is_this_file_compressed(biggie_filename) … … 3064 3065 fatal_error("bkpinfo->optimal_set_size is insanely small"); 3065 3066 } 3066 if ( partimagehack_fifo) {3067 file_to_openin = partimagehack_fifo;3067 if (ntfsprog_fifo) { 3068 file_to_openin = ntfsprog_fifo; 3068 3069 asprintf(&checksum_line, "IGNORE"); 3069 3070 log_msg(2, 3070 3071 "Not calculating checksum for %s: it would take too long", 3071 3072 biggie_filename); 3072 totallength = get_phys_size_of_drive(biggie_filename)*1024*1024LL; 3073 if ( !find_home_of_exe("ntfsresize")) { 3074 fatal_error("ntfsresize not found"); 3075 } 3076 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename); 3077 log_it("command = %s", command); 3078 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 3079 log_it("res of it = %s", tmp); 3080 totallength = atoll(tmp); 3073 3081 } else { 3074 3082 file_to_openin = biggie_filename; -
trunk/mondo/mondo/common/libmondo-archive.h
r262 r300 29 29 void set_bit_N_of_array(char *array, int N, bool true_or_false); 30 30 int slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename, 31 char * partimagehack_fifo,31 char *ntfsprog_fifo, 32 32 long biggie_file_number, long noof_biggie_files, 33 bool use_ partimagehack);33 bool use_ntfsprog); 34 34 int verify_data(struct s_bkpinfo *bkpinfo); 35 35 void wipe_archives(char *d); -
trunk/mondo/mondo/common/libmondo-files.c
r236 r300 711 711 char *biggielist; 712 712 char *comment; 713 char *tmp; 714 char *command; 713 715 714 716 /*@ long ******************************************************** */ … … 722 724 /*@ end vars *************************************************** */ 723 725 726 malloc_string(tmp); 727 malloc_string(command); 724 728 log_it("Calculating size of all biggiefiles (in total)"); 725 729 asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); … … 736 740 } 737 741 if (0 == strncmp(fname, "/dev/", 5)) { 738 file_len_K = get_phys_size_of_drive(fname) * 1024L; 742 if (is_dev_an_NTFS_dev(fname)) { 743 if ( !find_home_of_exe("ntfsresize")) { 744 fatal_error("ntfsresize not found"); 745 } 746 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 747 log_it("command = %s", command); 748 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 749 log_it("res of it = %s", tmp); 750 file_len_K = atoll(tmp) / 1024L; 751 } else { 752 file_len_K = get_phys_size_of_drive(fname) * 1024L; 753 } 739 754 } else { 740 755 file_len_K = (long) (length_of_file(fname) / 1024); … … 761 776 paranoid_fclose(fin); 762 777 log_it("Finished calculating total size of all biggiefiles"); 778 paranoid_free(tmp); 779 paranoid_free(command); 763 780 return (scratchL); 764 781 } -
trunk/mondo/mondo/common/libmondo-fork-EXT.h
r59 r300 14 14 char *cmd); 15 15 extern int copy_from_src_to_dest(FILE *, FILE *, char); 16 extern int feed_into_ partimage(char *input_device, char *output_fname);17 extern int feed_outfrom_ partimage(char *output_device, char *input_fifo);16 extern int feed_into_ntfsprog(char *input_device, char *output_fname); 17 extern int feed_outfrom_ntfsprog(char *output_device, char *input_fifo); -
trunk/mondo/mondo/common/libmondo-fork.c
r171 r300 1 /* $Id$ 2 subroutines for handling forking/pthreads/etc. 1 /* libmondo-fork.c 2 $Id$ 3 4 - subroutines for handling forking/pthreads/etc. 5 6 7 01/20/2006 8 - replaced partimagehack with ntfsclone 9 10 06/20/2004 11 - create fifo /var/log/partimagehack-debug.log and empty it 12 to keep ramdisk from filling up 13 14 04/13/2004 15 - >= should be <= g_loglevel 16 17 11/15/2003 18 - changed a few []s to char*s 19 20 10/12 21 - rewrote partimagehack handling (multiple fifos, chunks, etc.) 22 23 10/11 24 - partimagehack now has debug level of N (set in my-stuff.h) 25 26 10/08 27 - call to partimagehack when restoring will now log errors to /var/log/....log 28 29 10/06 30 - cleaned up logging a bit 31 32 09/30 33 - line 735 - missing char* cmd in sprintf() 34 35 09/28 36 - added run_external_binary_with_percentage_indicator() 37 - rewritten eval_call_to_make_ISO() 38 39 09/18 40 - call mkstemp instead of mktemp 41 42 09/13 43 - major NTFS hackage 44 45 09/12 46 - paranoid_system("rm -f /tmp/ *PARTIMAGE*") before calling partimagehack 47 48 09/11 49 - forward-ported unbroken feed_*_partimage() subroutines 50 from early August 2003 51 52 09/08 53 - detect & use partimagehack if it exists 54 55 09/05 56 - finally finished partimagehack hack :) 57 58 07/04 59 - added subroutines to wrap around partimagehack 60 61 04/27 62 - don't echo (...res=%d...) at end of log_it() 63 unnecessarily 64 - replace newtFinished() and newtInit() with 65 newtSuspend() and newtResume() 66 67 04/24 68 - added some assert()'s and log_OS_error()'s 69 70 04/09 71 - cleaned up run_program_and_log_output() 72 73 04/07 74 - cleaned up code a bit 75 - let run_program_and_log_output() accept -1 (only log if _no error_) 76 77 01/02/2003 78 - in eval_call_to_make_ISO(), append output to MONDO_LOGFILE 79 instead of a temporary stderr text file 80 81 12/10 82 - patch by Heiko Schlittermann to handle % chars in issue.net 83 84 11/18 85 - if mkisofs in eval_call_to_make_ISO() returns an error then return it, 86 whether ISO was created or not 87 88 10/30 89 - if mkisofs in eval_call_to_make_ISO() returns an error then find out if 90 the output (ISO) file has been created; if it has then return 0 anyway 91 92 08/01 - 09/30 93 - run_program_and_log_output() now takes boolean operator to specify 94 whether it will log its activities in the event of _success_ 95 - system() now includes 2>/dev/null 96 - enlarged some tmp[]'s 97 - added run_program_and_log_to_screen() and run_program_and_log_output() 98 99 07/24 100 - created 3 101 */ 4 102 … … 370 468 371 469 /** 372 * Thread callback to run a command (partimage) in the background.373 * @param xfb A transfer block of @c char, containing:374 * - xfb:[0] A marker, should be set to 2. Decremented to 1 while the command is running and 0 when it's finished.375 * - xfb:[1] The command's return value, if xfb:[0] is 0.376 * - xfb+2: A <tt>NULL</tt>-terminated string containing the command to be run.377 * @return NULL to pthread_join.378 */379 void *call_partimage_in_bkgd(void *xfb)380 {381 char *transfer_block;382 int retval = 0;383 384 g_buffer_pid = getpid();385 unlink("/tmp/null");386 log_msg(1, "starting");387 transfer_block = (char *) xfb;388 transfer_block[0]--; // should now be 1389 retval = system(transfer_block + 2);390 if (retval) {391 log_OS_error("partimage returned an error");392 }393 transfer_block[1] = retval;394 transfer_block[0]--; // should now be 0395 g_buffer_pid = 0;396 log_msg(1, "returning");397 pthread_exit(NULL);398 }399 400 401 /**402 * File to touch if we want partimage to wait for us.403 */404 #define PAUSE_PARTIMAGE_FNAME "/tmp/PAUSE-PARTIMAGE-FOR-MONDO"405 406 /**407 470 * Apparently used. @bug This has a purpose, but what? 408 471 */ … … 410 473 #define PIMP_END_SZ "ENDENDEND0xBBC10xBBC2T231hc81h42vws89ff3kff9a82gv34r7fghbka" 411 474 412 /** 413 * Marker to start the next subvolume for Partimage. 414 */ 415 #define NEXT_SUBVOL_PLEASE "I-grew-up-on-the-crime-side,-the-New-York-Times-side,-where-staying-alive-was-no-jive" 416 417 /** 418 * Marker to end the partimage file. 419 */ 420 #define NO_MORE_SUBVOLS "On-second-hand,momma-bounced-on-old-man,-and-so-we-moved-to-Shaolin-Land." 475 476 421 477 422 478 int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction) … … 559 615 } 560 616 561 562 617 /** 563 * Call partimage from @p input_device to @p output_fname. 564 * @param input_device The device to read. 565 * @param output_fname The file to write. 566 * @return 0 for success, nonzero for failure. 567 */ 568 int dynamically_create_pipes_and_copy_from_them_to_output_file(char 569 *input_device, char 570 *output_fname) 571 { 572 char *curr_fifo; 573 char *prev_fifo = NULL; 574 char *next_fifo; 575 char *command; 576 char *sz_call_to_partimage; 577 int fifo_number = 0; 578 struct stat buf; 579 pthread_t partimage_thread; 580 int res = 0; 581 char *tmpstub; 582 FILE *fout; 583 FILE *fin; 584 char *tmp; 585 586 log_msg(1, "g_tmpfs_mountpt = %s", g_tmpfs_mountpt); 587 if (g_tmpfs_mountpt && g_tmpfs_mountpt[0] 588 && does_file_exist(g_tmpfs_mountpt)) { 589 asprintf(&tmpstub, g_tmpfs_mountpt); 590 } else { 591 asprintf(&tmpstub, "/tmp"); 592 } 593 paranoid_system("rm -f /tmp/*PARTIMAGE*"); 594 asprintf(&command, "rm -Rf %s/pih-fifo-*", tmpstub); 595 paranoid_system(command); 596 paranoid_free(command); 597 598 asprintf(&tmp, "%s/pih-fifo-%ld", tmpstub, (long int) random()); 599 paranoid_free(tmpstub); 600 tmpstub = tmp; 601 paranoid_free(tmp); 602 603 mkfifo(tmpstub, S_IRWXU | S_IRWXG); // never used, though... 604 asprintf(&curr_fifo, "%s.%03d", tmpstub, fifo_number); 605 asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1); 606 mkfifo(curr_fifo, S_IRWXU | S_IRWXG); 607 mkfifo(next_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo already exists before we call partimage 608 asprintf(&sz_call_to_partimage, 609 "%c%cpartimagehack " PARTIMAGE_PARAMS 610 " save %s %s > /tmp/stdout 2> /tmp/stderr", 2, 0, input_device, 611 tmpstub); 612 log_msg(5, "curr_fifo = %s", curr_fifo); 613 log_msg(5, "next_fifo = %s", next_fifo); 614 log_msg(5, "sz_call_to_partimage call is '%s'", 615 sz_call_to_partimage + 2); 616 if (!lstat(output_fname, &buf) && S_ISREG(buf.st_mode)) { 617 log_msg(5, "Deleting %s", output_fname); 618 unlink(output_fname); 619 } 620 if (!(fout = fopen(output_fname, "w"))) { 621 fatal_error("Unable to openout to output_fname"); 622 } 623 res = 624 pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd, 625 (void *) sz_call_to_partimage); 626 if (res) { 627 fatal_error("Failed to create thread to call partimage"); 628 } 629 log_msg(1, "Running fore/back at same time"); 630 log_to_screen("Working with partimagehack..."); 631 while (sz_call_to_partimage[0] > 0) { 632 asprintf(&tmp, "%s\n", NEXT_SUBVOL_PLEASE); 633 if (fwrite(tmp, 1, 128, fout) != 128) { 634 fatal_error("Cannot write interim block"); 635 } 636 paranoid_free(tmp); 637 638 log_msg(5, "fifo_number=%d", fifo_number); 639 log_msg(4, "Cat'ting %s", curr_fifo); 640 if (!(fin = fopen(curr_fifo, "r"))) { 641 fatal_error("Unable to openin from fifo"); 642 } 643 if (prev_fifo != NULL) { 644 log_msg(5, "Deleting %s", prev_fifo); 645 unlink(prev_fifo); // just in case 646 paranoid_free(prev_fifo); 647 } 648 copy_from_src_to_dest(fin, fout, 'w'); 649 paranoid_fclose(fin); 650 fifo_number++; 651 652 prev_fifo = curr_fifo; 653 curr_fifo = next_fifo; 654 log_msg(5, "Creating %s", next_fifo); 655 asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1); 656 mkfifo(next_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo exists before we cat this one 657 system("sync"); 658 sleep(5); 659 } 660 asprintf(&tmp, "%s\n", NO_MORE_SUBVOLS); 661 if (fwrite(tmp, 1, 128, fout) != 128) { 662 fatal_error("Cannot write interim block"); 663 } 664 if (fwrite(tmp, 1, 128, fout) != 128) { 665 fatal_error("Cannot write interim block"); 666 } 667 if (fwrite(tmp, 1, 128, fout) != 128) { 668 fatal_error("Cannot write interim block"); 669 } 670 if (fwrite(tmp, 1, 128, fout) != 128) { 671 fatal_error("Cannot write interim block"); 672 } 673 paranoid_free(tmp); 674 paranoid_fclose(fout); 675 log_to_screen("Cleaning up after partimagehack..."); 676 log_msg(3, "Final fifo_number=%d", fifo_number); 677 paranoid_system("sync"); 678 unlink(next_fifo); 679 paranoid_free(next_fifo); 680 681 unlink(curr_fifo); 682 paranoid_free(curr_fifo); 683 684 unlink(prev_fifo); 685 paranoid_free(prev_fifo); 686 687 log_to_screen("Finished cleaning up."); 688 689 // if (!lstat(sz_wait_for_this_file, &statbuf)) 690 // { log_msg(3, "WARNING! %s was not processed.", sz_wait_for_this_file); } 691 log_msg(2, "Waiting for pthread_join() to join."); 692 pthread_join(partimage_thread, NULL); 693 res = sz_call_to_partimage[1]; 694 paranoid_free(sz_call_to_partimage); 695 log_msg(2, "pthread_join() joined OK."); 696 log_msg(1, "Partimagehack(save) returned %d", res); 697 unlink(tmpstub); 698 paranoid_free(tmpstub); 699 700 return (res); 701 } 702 703 704 /** 705 * Feed @p input_device through partimage to @p output_fname. 618 * Feed @p input_device through ntfsclone to @p output_fname. 706 619 * @param input_device The device to image. 707 620 * @param output_fname The file to write. 708 621 * @return 0 for success, nonzero for failure. 709 622 */ 710 int feed_into_ partimage(char *input_device, char *output_fname)623 int feed_into_ntfsprog(char *input_device, char *output_fname) 711 624 { 712 625 // BACKUP 713 int res; 626 int res = -1; 627 char*command; 714 628 715 629 if (!does_file_exist(input_device)) { 716 630 fatal_error("input device does not exist"); 717 631 } 718 if (!find_home_of_exe("partimagehack")) { 719 fatal_error("partimagehack not found"); 720 } 721 res = 722 dynamically_create_pipes_and_copy_from_them_to_output_file 723 (input_device, output_fname); 632 if ( !find_home_of_exe("ntfsclone")) { 633 fatal_error("ntfsclone not found"); 634 } 635 malloc_string(command); 636 sprintf(command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device); 637 res = run_program_and_log_output(command, 5); 638 paranoid_free(command); 724 639 return (res); 725 640 } … … 871 786 } 872 787 873 #define PIH_LOG "/var/log/partimage-debug.log"874 788 875 789 /** 876 * Feed @p input_fifo through partimage (restore) to @p output_device.877 * @param input_fifo The partimage file to read.790 * Feed @p input_fifo through ntfsclone (restore) to @p output_device. 791 * @param input_fifo The ntfsclone file to read. 878 792 * @param output_device Where to put the output. 879 * @return The return value of partimagehack (0 for success). 880 * @bug Probably unnecessary, as the partimage is just a sparse file. We could use @c dd to restore it. 793 * @return The return value of ntfsclone (0 for success). 881 794 */ 882 int feed_outfrom_ partimage(char *output_device, char *input_fifo)795 int feed_outfrom_ntfsprog(char *output_device, char *input_fifo) 883 796 { 884 797 // RESTORE 885 char *tmp; 886 char *stuff; 887 char *sz_call_to_partimage; 888 pthread_t partimage_thread; 889 int res; 890 char *curr_fifo; 891 char *prev_fifo = NULL; 892 char *oldest_fifo = NULL; 893 char *next_fifo; 894 char *afternxt_fifo; 895 int fifo_number = 0; 896 char *tmpstub; 897 FILE *fin; 898 FILE *fout; 899 900 log_msg(1, "output_device=%s", output_device); 901 log_msg(1, "input_fifo=%s", input_fifo); 902 asprintf(&tmpstub, "/tmp"); 903 904 log_msg(1, "tmpstub was %s", tmpstub); 905 asprintf(&stuff, tmpstub); 906 paranoid_free(tmpstub); 907 908 asprintf(&tmpstub, "%s/pih-fifo-%ld", stuff, (long int) random()); 909 paranoid_free(stuff); 910 911 log_msg(1, "tmpstub is now %s", tmpstub); 912 unlink("/tmp/PARTIMAGEHACK-POSITION"); 913 unlink(PAUSE_PARTIMAGE_FNAME); 914 paranoid_system("rm -f /tmp/*PARTIMAGE*"); 915 asprintf(&curr_fifo, "%s.%03d", tmpstub, fifo_number); 916 asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1); 917 asprintf(&afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2); 918 mkfifo(PIH_LOG, S_IRWXU | S_IRWXG); 919 mkfifo(curr_fifo, S_IRWXU | S_IRWXG); 920 mkfifo(next_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo already exists before we call partimage 921 mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG); 922 system("cat " PIH_LOG " > /dev/null &"); 923 log_msg(3, "curr_fifo = %s", curr_fifo); 924 log_msg(3, "next_fifo = %s", next_fifo); 925 if (!does_file_exist(input_fifo)) { 926 fatal_error("input fifo does not exist"); 927 } 928 if (!(fin = fopen(input_fifo, "r"))) { 929 fatal_error("Unable to openin from input_fifo"); 930 } 931 if (!find_home_of_exe("partimagehack")) { 932 fatal_error("partimagehack not found"); 933 } 934 asprintf(&sz_call_to_partimage, 935 "%c%cpartimagehack " PARTIMAGE_PARAMS 936 " restore %s %s > /dev/null 2>> %s", 2, 0, output_device, curr_fifo, 937 MONDO_LOGFILE); 938 log_msg(1, "output_device = %s", output_device); 939 log_msg(1, "curr_fifo = %s", curr_fifo); 940 log_msg(1, "sz_call_to_partimage+2 = %s", sz_call_to_partimage + 2); 941 res = 942 pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd, 943 (void *) sz_call_to_partimage); 944 if (res) { 945 fatal_error("Failed to create thread to call partimage"); 946 } 947 log_msg(1, "Running fore/back at same time"); 948 log_msg(2, " Trying to openin %s", input_fifo); 949 if (!does_file_exist(input_fifo)) { 950 log_msg(2, "Warning - %s does not exist", input_fifo); 951 } 952 while (!does_file_exist("/tmp/PARTIMAGEHACK-POSITION")) { 953 log_msg(6, "Waiting for partimagehack (restore) to start"); 954 sleep(1); 955 } 956 957 if (!(tmp = malloc(128))) { 958 fatal_error("Failed to malloc() tmp"); 959 } 960 while (sz_call_to_partimage[0] > 0) { 961 if (fread(tmp, 1, 128, fin) != 128) { 962 fatal_error("Cannot read introductory block"); 963 } 964 if (strstr(tmp, NEXT_SUBVOL_PLEASE)) { 965 log_msg(2, "Great. Next subvol coming up."); 966 } else if (strstr(tmp, NO_MORE_SUBVOLS)) { 967 log_msg(2, "Great. That was the last subvol."); 968 break; 969 } else { 970 log_msg(2, "WTF is this? '%s'", tmp); 971 fatal_error("Unknown interim block"); 972 } 973 if (feof(fin)) { 974 log_msg(1, "Eof(fin) detected. Breaking."); 975 break; 976 } 977 log_msg(3, "Processing subvol %d", fifo_number); 978 log_msg(5, "fifo_number=%d", fifo_number); 979 if (!(fout = fopen(curr_fifo, "w"))) { 980 fatal_error("Cannot openout to curr_fifo"); 981 } 982 copy_from_src_to_dest(fout, fin, 'r'); 983 paranoid_fclose(fout); 984 fifo_number++; 985 if (oldest_fifo != NULL) { 986 log_msg(6, "Deleting %s", oldest_fifo); 987 unlink(oldest_fifo); // just in case 988 paranoid_free(oldest_fifo); 989 } 990 oldest_fifo = prev_fifo; 991 prev_fifo = curr_fifo; 992 curr_fifo = next_fifo; 993 next_fifo = afternxt_fifo; 994 asprintf(&afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2); 995 log_msg(6, "Creating %s", afternxt_fifo); 996 mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo already exists before we access current fifo 997 fflush(fin); 998 // system("sync"); 999 usleep(1000L * 100L); 1000 } 1001 paranoid_free(tmp); 1002 paranoid_free(tmpstub); 1003 1004 paranoid_fclose(fin); 1005 paranoid_system("sync"); 1006 log_msg(1, "Partimagehack has finished. Great. Fin-closing."); 1007 log_msg(1, "Waiting for pthread_join"); 1008 pthread_join(partimage_thread, NULL); 1009 res = sz_call_to_partimage[1]; 1010 paranoid_free(sz_call_to_partimage); 1011 1012 log_msg(1, "Yay. Partimagehack (restore) returned %d", res); 1013 unlink(prev_fifo); 1014 paranoid_free(prev_fifo); 1015 1016 unlink(curr_fifo); 1017 paranoid_free(curr_fifo); 1018 1019 unlink(next_fifo); 1020 paranoid_free(next_fifo); 1021 1022 unlink(afternxt_fifo); 1023 paranoid_free(afternxt_fifo); 1024 1025 unlink(PIH_LOG); 1026 /* BERLIOS : pas de unlink(oldest_fifo) ??? */ 1027 paranoid_free(oldest_fifo); 1028 798 int res = -1; 799 char *command; 800 801 if ( !find_home_of_exe("ntfsclone")) { 802 fatal_error("ntfsclone not found"); 803 } 804 asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo); 805 res = run_program_and_log_output(command, 5); 806 paranoid_free(command); 1029 807 return (res); 1030 808 } -
trunk/mondo/mondo/common/libmondo-fork.h
r59 r300 15 15 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd); 16 16 int copy_from_src_to_dest(FILE *, FILE *, char); 17 int feed_into_ partimage(char *input_device, char *output_fname);18 int feed_outfrom_ partimage(char *output_device, char *input_fifo);17 int feed_into_ntfsprog(char *input_device, char *output_fname); 18 int feed_outfrom_ntfsprog(char *output_device, char *input_fifo); -
trunk/mondo/mondo/common/libmondo-verify.c
r274 r300 339 339 if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) { 340 340 log_msg(3, 341 "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via partimagehack, not dd.",341 "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via ntfsclone, not dd.", 342 342 biggiestruct.filename); 343 343 log_msg(3, -
trunk/mondo/mondo/common/mondostructures.h
r171 r300 342 342 * 343 343 * This is useful for backing up NTFS partitions. 344 * @c partimage is used to back up only the used sectors, so the space tradeoff is not bad.344 * @c ntfsclone is used to back up only the used sectors, so the space tradeoff is not bad. 345 345 * However, several caveats apply to such a partition: 346 346 * - It must not be mounted during the backup 347 * - It must be in a format that partimage knows how to handle347 * - It must be in a format that ntfsclone knows how to handle, i.e. NTFS 348 348 * - It cannot be verified during the verify or compare phase 349 349 * - It may not be resized or selectively restored at restore-time (all or nothing) … … 661 661 */ 662 662 struct stat properties; 663 bool use_ partimagehack;663 bool use_ntfsprog; 664 664 }; 665 665 -
trunk/mondo/mondo/common/my-stuff.h
r238 r300 151 151 #define BLK_STOP_BIGGIEFILES 39 ///< Marker block: stop the biggiefile section. 152 152 #define BLK_START_A_NORMBIGGIE 40 ///< Marker block: start a normal biggiefile. 153 #define BLK_START_A_PIHBIGGIE 41 ///< Marker block: start a partimagehack'd biggiefile153 #define BLK_START_A_PIHBIGGIE 41 ///< Marker block: start a ntfsprog'd biggiefile 154 154 #define BLK_START_EXTENDED_ATTRIBUTES 45 ///< Marker block: start xattr/acl info 155 155 #define BLK_STOP_EXTENDED_ATTRIBUTES 46 ///< Marker block: stop xattr/acl info … … 389 389 #define DEFAULT_DEBUG_LEVEL 4 ///< By default, don't log messages with a loglevel higher than this. 390 390 391 #define SZ_ PARTIMAGE_VOLSIZE "1048576" // was 4096392 #define PARTIMAGE_PARAMS "-z0 -V" SZ_PARTIMAGE_VOLSIZE " -o -b -d -g1"391 #define SZ_NTFSPROG_VOLSIZE "1048576" // was 4096 392 #define NTFSPROG_PARAMS "-z0 -V" SZ_NTFSPROG_VOLSIZE " -o -b -d -g1" 393 393 394 394 #define MNT_CDROM "/mnt/cdrom" -
trunk/mondo/mondo/common/newt-specific.c
r219 r300 281 281 kill_anything_like_this("/mondo/do-not"); 282 282 kill_anything_like_this("tmp.mondo"); 283 kill_anything_like_this(" partimagehack");283 kill_anything_like_this("ntfsclone"); 284 284 sync(); 285 285 asprintf(&tmp, "umount %s", g_tmpfs_mountpt); -
trunk/mondo/mondo/mondoarchive/main.c
r262 r300 157 157 158 158 diffs = 0; 159 unlink("/var/log/partimagehack-debug.log");160 159 printf("Initializing...\n"); 161 160 if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) { -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r292 r300 572 572 asprintf(&tmp, flag_val['x']); 573 573 bkpinfo->image_devs = tmp; 574 if (run_program_and_log_output("which partimagehack", 2)) {575 fatal_error("Please install partimagehack RPM/tarball.");574 if (run_program_and_log_output("which ntfsclone", 2)) { 575 fatal_error("Please install ntfsprogs package/tarball."); 576 576 } 577 577 } -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r274 r300 1368 1368 /** malloc ***/ 1369 1369 char *checksum, *outfile_fname, *tmp, *bzip2_command, 1370 * partimagehack_command, *suffix, *sz_devfile;1370 *ntfsprog_command, *suffix, *sz_devfile; 1371 1371 char *bigblk; 1372 1372 char *p; … … 1375 1375 long sliceno; 1376 1376 long siz; 1377 char partimagehack_fifo[MAX_STR_LEN];1377 char ntfsprog_fifo[MAX_STR_LEN]; 1378 1378 char *file_to_openout = NULL; 1379 1379 struct s_filename_and_lstat_info biggiestruct; 1380 1380 struct utimbuf the_utime_buf, *ubuf; 1381 bool use_ partimage_hack = FALSE;1381 bool use_ntfsprog_hack = FALSE; 1382 1382 pid_t pid; 1383 1383 int res = 0; … … 1394 1394 malloc_string(tmp); 1395 1395 malloc_string(bzip2_command); 1396 malloc_string( partimagehack_command);1396 malloc_string(ntfsprog_command); 1397 1397 malloc_string(suffix); 1398 1398 malloc_string(sz_devfile); … … 1451 1451 1452 1452 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1453 if (biggiestruct.use_ partimagehack) {1453 if (biggiestruct.use_ntfsprog) { 1454 1454 if (strncmp(biggiestruct.filename, "/dev/", 5)) { 1455 1455 log_msg(1, 1456 "I was in error when I set biggiestruct.use_ partimagehackto TRUE.");1456 "I was in error when I set biggiestruct.use_ntfsprog to TRUE."); 1457 1457 log_msg(1, "%s isn't even in /dev", biggiestruct.filename); 1458 biggiestruct.use_ partimagehack= FALSE;1459 } 1460 } 1461 1462 if (biggiestruct.use_ partimagehack) // if it's an NTFS device1458 biggiestruct.use_ntfsprog = FALSE; 1459 } 1460 } 1461 1462 if (biggiestruct.use_ntfsprog) // if it's an NTFS device 1463 1463 // if (!strncmp ( biggiestruct.filename, "/dev/", 5)) 1464 1464 { 1465 1465 g_loglevel = 4; 1466 use_ partimage_hack = TRUE;1466 use_ntfsprog_hack = TRUE; 1467 1467 log_msg(2, 1468 "Calling partimagehackin background because %s is an NTFS /dev entry",1468 "Calling ntfsclone in background because %s is an NTFS /dev entry", 1469 1469 outfile_fname); 1470 1470 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1471 1471 (int) (random() % 32768)); 1472 1472 mkfifo(sz_devfile, 0x770); 1473 strcpy( partimagehack_fifo, sz_devfile);1474 file_to_openout = partimagehack_fifo;1473 strcpy(ntfsprog_fifo, sz_devfile); 1474 file_to_openout = ntfsprog_fifo; 1475 1475 switch (pid = fork()) { 1476 1476 case -1: … … 1478 1478 case 0: 1479 1479 log_msg(3, 1480 "CHILD - fip - calling feed_outfrom_ partimage(%s, %s)",1481 biggiestruct.filename, partimagehack_fifo);1480 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", 1481 biggiestruct.filename, ntfsprog_fifo); 1482 1482 res = 1483 feed_outfrom_ partimage(biggiestruct.filename,1484 partimagehack_fifo);1483 feed_outfrom_ntfsprog(biggiestruct.filename, 1484 ntfsprog_fifo); 1485 1485 // log_msg(3, "CHILD - fip - exiting"); 1486 1486 exit(res); … … 1488 1488 default: 1489 1489 log_msg(3, 1490 "feed_into_ partimage() called in background --- pid=%ld",1490 "feed_into_ntfsprog() called in background --- pid=%ld", 1491 1491 (long int) (pid)); 1492 1492 } 1493 1493 } else { 1494 use_ partimage_hack = FALSE;1495 partimagehack_fifo[0] = '\0';1494 use_ntfsprog_hack = FALSE; 1495 ntfsprog_fifo[0] = '\0'; 1496 1496 file_to_openout = outfile_fname; 1497 1497 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way … … 1520 1520 return (1); 1521 1521 } 1522 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack--> hard disk itself1522 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself 1523 1523 1524 1524 for (sliceno = 1, finished = FALSE; !finished;) { … … 1629 1629 g_loglevel = old_loglevel; 1630 1630 1631 if (use_ partimage_hack) {1632 log_msg(3, "Waiting for partimage to finish");1631 if (use_ntfsprog_hack) { 1632 log_msg(3, "Waiting for ntfsclone to finish"); 1633 1633 sprintf(tmp, 1634 " ps ax | grep \" partimagehack\" | grep -v grep > /dev/null 2> /dev/null");1634 " ps ax | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1635 1635 while (system(tmp) == 0) { 1636 1636 sleep(1); 1637 1637 } 1638 log_it("OK, partimage has really finished");1638 log_it("OK, ntfsclone has really finished"); 1639 1639 } 1640 1640 … … 1652 1652 paranoid_free(tmp); 1653 1653 paranoid_free(bzip2_command); 1654 paranoid_free( partimagehack_command);1654 paranoid_free(ntfsprog_command); 1655 1655 paranoid_free(suffix); 1656 1656 paranoid_free(sz_devfile); … … 1682 1682 long long biggiefile_size, //UNUSED 1683 1683 struct s_node *filelist, 1684 int use_ partimagehack,1684 int use_ntfsprog, 1685 1685 char *pathname_of_last_file_restored) 1686 1686 { … … 1692 1692 char *command; 1693 1693 char *outfile_fname; 1694 char * partimagehack_command;1694 char *ntfsprog_command; 1695 1695 char *sz_devfile; 1696 char * partimagehack_fifo;1696 char *ntfsprog_fifo; 1697 1697 char *file_to_openout = NULL; 1698 1698 … … 1706 1706 long long slice_siz; 1707 1707 bool dummy_restore = FALSE; 1708 bool use_ partimage_hack = FALSE;1708 bool use_ntfsprog_hack = FALSE; 1709 1709 pid_t pid; 1710 1710 struct s_filename_and_lstat_info biggiestruct; … … 1713 1713 1714 1714 malloc_string(tmp); 1715 malloc_string( partimagehack_fifo);1715 malloc_string(ntfsprog_fifo); 1716 1716 malloc_string(outfile_fname); 1717 1717 malloc_string(command); 1718 1718 malloc_string(sz_devfile); 1719 malloc_string( partimagehack_command);1719 malloc_string(ntfsprog_command); 1720 1720 old_loglevel = g_loglevel; 1721 1721 assert(bkpinfo != NULL); … … 1724 1724 1725 1725 pathname_of_last_file_restored[0] = '\0'; 1726 if (use_ partimagehack== BLK_START_A_PIHBIGGIE) {1727 use_ partimagehack= 1;1726 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) { 1727 use_ntfsprog = 1; 1728 1728 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1729 } else if (use_ partimagehack== BLK_START_A_NORMBIGGIE) {1730 use_ partimagehack= 0;1729 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) { 1730 use_ntfsprog = 0; 1731 1731 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1732 1732 } else { 1733 use_ partimagehack= 0;1733 use_ntfsprog = 0; 1734 1734 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1735 1735 } … … 1757 1757 } 1758 1758 1759 if (use_ partimagehack) {1759 if (use_ntfsprog) { 1760 1760 if (strncmp(orig_bf_fname, "/dev/", 5)) { 1761 1761 log_msg(1, 1762 "I was in error when I set use_ partimagehackto TRUE.");1762 "I was in error when I set use_ntfsprog to TRUE."); 1763 1763 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1764 use_ partimagehack= FALSE;1765 } 1766 } 1767 1768 if (use_ partimagehack) {1764 use_ntfsprog = FALSE; 1765 } 1766 } 1767 1768 if (use_ntfsprog) { 1769 1769 g_loglevel = 4; 1770 1770 strcpy(outfile_fname, orig_bf_fname); 1771 use_ partimage_hack = TRUE;1771 use_ntfsprog_hack = TRUE; 1772 1772 log_msg(2, 1773 "Calling partimagehackin background because %s is a /dev entry",1773 "Calling ntfsclone in background because %s is a /dev entry", 1774 1774 outfile_fname); 1775 1775 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1776 1776 (int) (random() % 32768)); 1777 1777 mkfifo(sz_devfile, 0x770); 1778 strcpy( partimagehack_fifo, sz_devfile);1779 file_to_openout = partimagehack_fifo;1778 strcpy(ntfsprog_fifo, sz_devfile); 1779 file_to_openout = ntfsprog_fifo; 1780 1780 switch (pid = fork()) { 1781 1781 case -1: … … 1783 1783 case 0: 1784 1784 log_msg(3, 1785 "CHILD - fip - calling feed_outfrom_ partimage(%s, %s)",1786 outfile_fname, partimagehack_fifo);1785 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", 1786 outfile_fname, ntfsprog_fifo); 1787 1787 res = 1788 feed_outfrom_ partimage(outfile_fname, partimagehack_fifo);1788 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo); 1789 1789 // log_msg(3, "CHILD - fip - exiting"); 1790 1790 exit(res); … … 1792 1792 default: 1793 1793 log_msg(3, 1794 "feed_into_ partimage() called in background --- pid=%ld",1794 "feed_into_ntfsprog() called in background --- pid=%ld", 1795 1795 (long int) (pid)); 1796 1796 } … … 1804 1804 orig_bf_fname); 1805 1805 } 1806 use_ partimage_hack = FALSE;1807 partimagehack_fifo[0] = '\0';1806 use_ntfsprog_hack = FALSE; 1807 ntfsprog_fifo[0] = '\0'; 1808 1808 file_to_openout = outfile_fname; 1809 1809 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way … … 1882 1882 pathname_of_last_file_restored); 1883 1883 1884 if (use_ partimage_hack) {1885 log_msg(3, "Waiting for partimage to finish");1884 if (use_ntfsprog_hack) { 1885 log_msg(3, "Waiting for ntfsclone to finish"); 1886 1886 sprintf(tmp, 1887 " ps ax | grep \" partimagehack\" | grep -v grep > /dev/null 2> /dev/null");1887 " ps ax | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1888 1888 while (system(tmp) == 0) { 1889 1889 sleep(1); 1890 1890 } 1891 log_msg(3, "OK, partimage has really finished");1891 log_msg(3, "OK, ntfsclone has really finished"); 1892 1892 } 1893 1893 … … 1906 1906 paranoid_free(outfile_fname); 1907 1907 paranoid_free(command); 1908 paranoid_free( partimagehack_command);1908 paranoid_free(ntfsprog_command); 1909 1909 paranoid_free(sz_devfile); 1910 paranoid_free( partimagehack_fifo);1910 paranoid_free(ntfsprog_fifo); 1911 1911 g_loglevel = old_loglevel; 1912 1912 return (retval);
Note:
See TracChangeset
for help on using the changeset viewer.