From: <de...@de...> - 2011-09-04 05:33:19
|
Author: PeterThoeny Date: 2011-09-04 00:33:10 -0500 (Sun, 04 Sep 2011) New Revision: 22201 Trac url: http://develop.twiki.org/trac/changeset/22201 Modified: twiki/trunk/BackupRestorePlugin/lib/TWiki/Plugins/BackupRestorePlugin/Core.pm Log: Item6795: Add restore from backup feature - unzip to temporary area Modified: twiki/trunk/BackupRestorePlugin/lib/TWiki/Plugins/BackupRestorePlugin/Core.pm =================================================================== --- twiki/trunk/BackupRestorePlugin/lib/TWiki/Plugins/BackupRestorePlugin/Core.pm 2011-09-03 23:41:42 UTC (rev 22200) +++ twiki/trunk/BackupRestorePlugin/lib/TWiki/Plugins/BackupRestorePlugin/Core.pm 2011-09-04 05:33:10 UTC (rev 22201) @@ -699,7 +699,37 @@ return ''; } - #FIXME + my $text = _readFile( $this->{DaemonDir} . '/file_name.txt' ); + if( $text !~ m/type: 2-/s ) { + $this->_setError( "ERROR: Restore can only be called from the console" ); + return ''; + } + my @webs = + map{ s/\:/\//go; $_; } + map{ /^web\:(.*)\: .*/; $1; } + grep{ /^web\:.*\: / } + split( /\n/, $text ); + + unless( scalar @webs ) { + $this->_setError( "NOTE: Nothing to do, no webselected to restore" ); + return ''; + } + + # remove and re-create temp dir for restore + my $tmpRestoreDir = $this->{DaemonDir} . '/_tmp_restore'; + File::Path::rmtree( $tmpRestoreDir ) if( $tmpRestoreDir ); + $this->_makeDir( $tmpRestoreDir ) unless( -e $tmpRestoreDir ); + return $text if( $this->_isError() ); + + # unzip into temp dir + chdir( $tmpRestoreDir ); + $this->_unZip( $name ); + if( $this->_isError() ) { + File::Path::rmtree( $tmpRestoreDir ); + return $text; + } + + #FIXME restore webs _saveFile( $this->{DaemonDir} . '/blah1.txt', 'restore!!' ); sleep( 30 ); _saveFile( $this->{DaemonDir} . '/blah2.txt', 'restore!!' ); @@ -782,6 +812,12 @@ } #================================================================== +sub _isError { + my( $this ) = @_; + $this->{error} ? return 1 : return 0; +} + +#================================================================== sub _renderError { my( $this ) = @_; |