Tags:
create new tag
, view all tags

LdapContrib Enhancement: Make file backup of LdapContrib cache file when it's updated

Motivation

Using LdapContrib, the cache file is in the center of it all. Should this somehow get corrupted, one has to act fast. Ideally you would re-create the cache and go from there, this might however not work if:

  • You don't know the reason the cache got corrupted, and it will not fix it self with a cache refresh.
  • You have a large amount of users or groups, and refreshing the cache takes a long time (say > 10 minutes).
By backing up the last production cache files, one can easily switch to one of these and inflict minimal downtime for the TWiki, should the production cache get corrupted.

Impact

Storing file backups of the production cache file will take up some disk space, this feature should therefore be optional. As an extra feature, the user should perhaps be able to select the number of backups.

Implementationn

A configuration flag is added to LdapContrib: $TWiki::cfg{Ldap}{BackupCacheFile}

Right before the freshly updated temporary cache is replacing the production cache, the production cache is backed up:

+  $this->backupCacheFile() if $this->{backupCacheFile};

   #writeDebug("replacing working copy");
   rename $tempCacheFile,$this->{cacheFile};

The subroutine:

=pod

---++++ backupCacheFile() -> void 

Before replacing the freshly created temporary cache with the production cache file, backup the file.

=cut

sub backupCacheFile {
  my ($this) = @_;
  my $workArea = $this->{session}->{store}->getWorkArea('LdapContrib');
  my @dbFiles = glob( "$workArea/*.db");
  unlink TWiki::Sandbox::untaintUnchecked($dbFiles[0]) if @dbFiles > 7;

  my ($sec,$min,$hour,$mday,$mon,$year) = (localtime(time))[0 .. 5];
  $year += 1900;
  $mon++;

  copy("$workArea/cache.db", sprintf("%s_%u-%02d-%02d %02d:%02d:%02d.db", "$workArea/cache", $year, $mon, $mday, $hour, $min, $sec));
}

-- Contributors: Terje Ness Andersen - 2013-08-27

Discussion

Looks good. I recommend using file names that work across all platforms, e.g. I recommend to avoid special chars. Example: cache.db.2013-08-28-19-03-47 or cache.db.2013-08-28-19-03-47.

Also, are glob and copy in the standard distribution of Perl 5.8.0 (minimum for TWiki) ? If not use alternate ways or document new dependency.

-- Peter Thoeny - 2013-08-29

BTW, I changed the form on this topic to ChangeProposalForm. If you fill out the form at TWikiFeatureProposals you will get automatically the proper TWiki change proposal form.

-- Peter Thoeny - 2013-08-29

Good point about making the file names work across all platforms.

glob is,, copy is a part of File::Copy which has been in the Perl core since 5.002 according to Module::CoreList. Does it have to be listed as a dependency still?

Thanks for fixing the form!

-- Terje Ness Andersen - 2013-08-29

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2013-09-03 - TerjeAndersen
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.