backup-file — backup Interchange file
| Attribute | Pos. | Req. | Default | Description |
|---|---|---|---|---|
| file | Yes | Yes | File to back-up | |
| interpolate | 0 | interpolate output? | ||
| hide | 0 | Hide the tag return value? |
The tag allows backing up of Interchange files.
Files are simply copied
to the backup/ subdirectory of
the catalog root directory (CATROOT).
File paths are preserved during copy; a target catalog file of say,
pages/index.html would be saved to
backup/pages/index.html.
You can copy filenames specified with absolute paths, and in fact, you can backup any file that the Interchange process can read.
Example: Backing-up catalog index page
[either] [tmp name=backup set="[backup-file pages/index.html]" hide=1] [or] [scratch ui_error] [/either]
Example: Backing-up system password file
[either] [tmp name=backup set="[backup-file /etc/passwd]" hide=1] [or] [scratch ui_error] [/either]
The backup directory and the full pathname are automatically created if they don't already exist.
Interchange 5.9.0:
Source: code/UI_Tag/backup_file.coretag
Lines: 47
# Copyright 2002-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: backup_file.coretag,v 1.5 2007-03-30 23:40:54 pajamian Exp $
UserTag backup-file Order file
UserTag backup-file AddAttr
UserTag backup-file Version $Revision: 1.5 $
UserTag backup-file Routine <<EOR
require File::Copy;
require File::Path;
require File::Basename;
sub {
my ($file, $opt) = @_;
my $bu_file = "backup/$file";
$bu_file =~ s://+:/:g ;
$bu_file =~ m:(.*)/: ;
my $bu_dir = $1;
eval {
die ::errmsg("Cannot figure out backup directory from %s", $bu_file)
if ! $bu_dir;
if (! -d $bu_dir) {
File::Path::mkpath($bu_dir)
or die ::errmsg("Cannot make backup directory %s: %s", $bu_dir, $!);
}
if (-f $bu_file) {
my $fn = $bu_file;
$fn =~ s:.*/::;
UI::Primitive::rotate($fn, { Directory => $bu_dir } )
or die ::errmsg("Cannot make backup of %s: %s", $bu_file, $!);
}
#::logDebug("ready to copy $file to $bu_file");
File::Copy::copy($file, $bu_file)
or die ::errmsg("Copy %s to %s: %s", $file, $bu_file, $!);
};
if ($@) {
$::Scratch->{ui_error} = $@;
::logError($::Scratch->{ui_error});
return undef;
}
return 1;
}
EOR