Changeset 27ca736257eadf7cced2fd99742d329f1cbe28d4
- Timestamp:
- 07/13/09 21:09:38
(4 years ago)
- Author:
- Mark Harrison <mark@omniti.com>
- git-committer:
- Mark Harrison <mark@omniti.com> 1247519378 +0000
- git-parent:
[5a3ecc112d3ac7b68e1badac3074f24cc6022fb3]
- git-author:
- Mark Harrison <mark@omniti.com> 1247519378 +0000
- Message:
Archive support for datasets
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r5a3ecc1 |
r27ca736 |
|
| 511 | 511 | my @F = split(' '); |
|---|
| 512 | 512 | my ($rawfs, $snap) = split('@', $F[0]); |
|---|
| 513 | | #$fs =~ s/$storefs\/?//; |
|---|
| 514 | | my $fs = get_real_fs_name($rawfs); |
|---|
| 515 | 513 | my ($whence) = ($snap =~ /(\d+)/); |
|---|
| 516 | 514 | next unless $whence; |
|---|
| | 515 | my $fs = get_real_fs_name($rawfs); |
|---|
| 517 | 516 | # Treat a dataset backup as a full backup from the point of view of the |
|---|
| 518 | 517 | # backup lists |
|---|
| … | … | |
| 845 | 844 | my ($mountpoint) = @_; |
|---|
| 846 | 845 | my $fs; |
|---|
| 847 | | my $rv = open(ZFSLIST, "__ZFS__ list -H |"); |
|---|
| | 846 | my $rv = open(ZFSLIST, "__ZFS__ list -t filesystem -H |"); |
|---|
| 848 | 847 | die "Unable to determine zfs filesystem for $mountpoint" unless $rv; |
|---|
| 849 | 848 | while (<ZFSLIST>) { |
|---|
| … | … | |
| 1004 | 1003 | my $backup_info = scan_for_backups($store); |
|---|
| 1005 | 1004 | my $tf = config_get($host, 'time_format'); |
|---|
| 1006 | | my @files; |
|---|
| | 1005 | my (@files, @datasets); |
|---|
| 1007 | 1006 | foreach my $disk (sort keys %{$backup_info}) { |
|---|
| 1008 | 1007 | my $info = $backup_info->{$disk}; |
|---|
| … | … | |
| 1042 | 1041 | foreach (@backup_points) { |
|---|
| 1043 | 1042 | pretty_print_backup($info, $host, $_); |
|---|
| 1044 | | push @files, exists($info->{full}->{$_}) ? $info->{full}->{$_}->{file} : $info->{incremental}->{$_}->{file}; |
|---|
| | 1043 | if(exists($info->{full}->{$_}->{file})) { |
|---|
| | 1044 | push @files, $info->{full}->{$_}->{file}; |
|---|
| | 1045 | } elsif(exists($info->{incremental}->{$_}->{file})) { |
|---|
| | 1046 | push @files, $info->{incremental}->{$_}->{file}; |
|---|
| | 1047 | } elsif(exists($info->{full}->{$_}->{dataset})) { |
|---|
| | 1048 | push @datasets, $info->{full}->{$_}->{dataset} |
|---|
| | 1049 | } |
|---|
| 1045 | 1050 | } |
|---|
| 1046 | 1051 | print "\n"; |
|---|
| 1047 | 1052 | } |
|---|
| 1048 | | if($ARCHIVE && scalar(@files)) { |
|---|
| 1049 | | my $archive = config_get($host, 'archive'); |
|---|
| 1050 | | $archive =~ s/%h/$host/g; |
|---|
| 1051 | | if(! -d $archive) { |
|---|
| 1052 | | mkdir $archive || die "Cannot mkdir($archive)\n"; |
|---|
| 1053 | | } |
|---|
| 1054 | | print "\nAre you sure you would like to archive ".scalar(@files)." file(s)? "; |
|---|
| | 1053 | if($ARCHIVE && (scalar(@files) || scalar(@datasets))) { |
|---|
| | 1054 | print "\nAre you sure you would like to archive ".scalar(@files). |
|---|
| | 1055 | " file(s) and ".scalar(@datasets)." dataset(s)? "; |
|---|
| 1055 | 1056 | while(($_ = <>) !~ /(?:y|n|yes|no)$/i) { |
|---|
| 1056 | | print "Are you sure you would like to archive ".scalar(@files)." file(s)? "; |
|---|
| | 1057 | print "\nAre you sure you would like to archive ".scalar(@files). |
|---|
| | 1058 | " file(s) and ".scalar(@datasets)." dataset(s)? "; |
|---|
| 1057 | 1059 | } |
|---|
| 1058 | 1060 | if(/^y/i) { |
|---|
| 1059 | | foreach my $file (@files) { |
|---|
| 1060 | | (my $afile = $file) =~ s/^$store/$archive/; |
|---|
| 1061 | | move($file, $afile) || print "Error archiving $file: $!\n"; |
|---|
| | 1061 | if (@files) { |
|---|
| | 1062 | my $archive = config_get($host, 'archive'); |
|---|
| | 1063 | $archive =~ s/%h/$host/g; |
|---|
| | 1064 | if(! -d $archive) { |
|---|
| | 1065 | mkdir $archive || die "Cannot mkdir($archive)\n"; |
|---|
| | 1066 | } |
|---|
| | 1067 | foreach my $file (@files) { |
|---|
| | 1068 | (my $afile = $file) =~ s/^$store/$archive/; |
|---|
| | 1069 | move($file, $afile) || print "Error archiving $file: $!\n"; |
|---|
| | 1070 | } |
|---|
| | 1071 | } |
|---|
| | 1072 | if (@datasets) { |
|---|
| | 1073 | my $archive = config_get($host, 'archive'); |
|---|
| | 1074 | my $storefs = get_fs_from_mountpoint($store); |
|---|
| | 1075 | (my $basearchive = $archive) =~ s/\/?%h//g; |
|---|
| | 1076 | my $basearchivefs; |
|---|
| | 1077 | eval { |
|---|
| | 1078 | $basearchivefs = get_fs_from_mountpoint($basearchive); |
|---|
| | 1079 | }; |
|---|
| | 1080 | die "Unable to find archive filesystem. The archive directory must be the root of a zfs filesystem to archive datasets." if $@; |
|---|
| | 1081 | my $archivefs = "$basearchivefs/$host"; |
|---|
| | 1082 | `__ZFS__ create $archivefs`; # We don't care if this fails |
|---|
| | 1083 | my %seen = (); |
|---|
| | 1084 | foreach my $dataset (@datasets) { |
|---|
| | 1085 | $dataset =~ s/@.*$//; # Only rename filesystems, not snapshots |
|---|
| | 1086 | next if $seen{$dataset}++; # Only rename a filesystem once |
|---|
| | 1087 | (my $adataset = $dataset) =~ s/^$storefs/$archivefs/; |
|---|
| | 1088 | `__ZFS__ rename $dataset $adataset`; |
|---|
| | 1089 | if ($?) { |
|---|
| | 1090 | print "Error archiving $dataset\n"; |
|---|
| | 1091 | } |
|---|
| | 1092 | } |
|---|
| 1062 | 1093 | } |
|---|
| 1063 | 1094 | } |
|---|