Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- @model_id=(101);
- $dhcp_id=100;
- $vz_pr_path='/var/lib/vz/private/';
- $cache_path='/var/cache/netboot/';
- $out_path="/var/lib/vz/root/$dhcp_id/var/lib/tftpboot/images/";
- for($i=0;$model_id[$i];$i++)
- {
- $cur_stamp=`stat $vz_pr_path$model_id[$i]/var/lib/apt/extended_states -c %Y`;
- if (! -e $cache_path . $model_id[$i]) #No checkpoint
- {
- write_stamp($model_id[$i]);
- build_img($model_id[$i],$cur_stamp);
- }
- else
- {
- $last_stamp=`cat $cache_path$model_id[$i]`;
- if ($cur_stamp > $last_stamp)
- {
- write_stamp($model_id[$i]);
- build_img($model_id[$i],$cur_stamp);
- }
- }
- }
- sub build_img
- {
- my $id=shift(@_);
- my $stamp=shift(@_);
- use File::Copy;
- $name=`vzlist -a|grep $id|awk '{print \$5}'`;
- chomp($name);
- @date=localtime($stamp);
- $date[5]+=1900;$date[4]=sprintf("%02d",++$date[4]);$date[3]=sprintf("%02d",$date[3]);$date[2]=sprintf("%02d",$date[2]);$date[1]=sprintf("%02d",$date[1]);
- $date="$date[5]-$date[4]-$date[3]_$date[2]-$date[1]";
- mkdir $out_path . $name;
- $img_filename="$out_path$name/$date";
- #Stop model
- system("vzctl stop $id");
- #Convert hardlinks
- system("nb_links_breaker $vz_pr_path$model_id[$i]/");
- #Remove /var/lib/cache/apt
- system("rm $vz_pr_path$model_id[$i]/var/cache/apt/archives/*.deb");
- #Make cpio
- system("cd $vz_pr_path$model_id[$i];find | cpio -H newc -o > $img_filename");
- #Start model
- system("vzconvert $id;vzctl start $id");
- #Compress
- system("gzip -9 $img_filename");
- #Update link "current"
- system("cd $out_path$name;rm current;ln -s $date.gz current");
- }
- sub write_stamp
- {
- my $id=shift(@_);
- `stat $vz_pr_path$model_id[$i]/var/lib/apt/extended_states -c %Y > $cache_path$model_id[$i]`;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement