Another possibility is a mod that I've done
to save disk space by
keeping just one backup per database, overwriting the old
backups each time (instead of keeping lots of old backups,
one per day).
This mod allows to overwrite the backup with the new data up to
once a day (86400 seconds) when building, but you can adjust this
number.
This works well for me, but I can not guarantee what will happen
in other servers. It's necessary, as with any mod, to keep a copy
of the original version, just in case. If this works for you, you may
delete or keep the old backups (wich have the dates in the names;
this will not happen more, using this mod).
To try this mod, you need to have an
admin/backup/time.bak file previously (the normal 644 automatic permission is sufficient),
for example an empty file or with a low number written as text,
and to replace
sub build_backup of the
nph-build.cgi file
(
Links 2.0) with the following (the old version of
build_backup is kept but disabled with "#"):
Code:
# ***************************************** modification - begin ****************
#sub build_backup {
## --------------------------------------------------------
## Backs up important database files.
##
# my $date = &get_date;
# if (-e "$db_script_path/backup/$date.links.db") {
# print "\tBackup exists for today.. Skipping\n";
# return;
# }
#
## Try to do it the right way..
# eval { require File::Copy; };
# if (!$@) {
# print "\tBacking up links, category and email database (File::Copy) ... \n";
# &File::Copy::copy ("$db_script_path/data/links.db", "$db_script_path/backup/$date.links.db") or &cgierr ("Unable to copy links backup. Reason: $!");
# &File::Copy::copy ("$db_script_path/data/categories.db", "$db_script_path/backup/$date.category.db") or &cgierr ("Unable to copy category backup. Reason: $!");
# &File::Copy::copy ("$db_script_path/data/email.db", "$db_script_path/backup/$date.email.db") or &cgierr ("Unable to copy email backup. Reason: $!");
# }
## Otherwise, the ugly way.
# else {
# print "\tBacking up links, category and email database (Regular - $@) ... \n";
# foreach (qw!links categories email!) {
# open (TMP, "$db_script_path/data/$_.db") or &cgierr ("Unable to open $db_script_path/data/$_.db. Reason: $!");
# open (TMPOUT, ">$db_script_path/backup/$date.$_.db") or &cgierr ("Unable to open $db_script_path/$date.$_.db. Reason: $!");
# while (<TMP>) {
# print TMPOUT;
# }
# close TMP;
# close TMPOUT;
# }
# }
#}
sub build_backup {
# --------------------------------------------------------
# Backs up important database files.
#
my ($last_date, $date);
open (TIMEBAK, "<$db_script_path/backup/time.bak") or &cgierr ("Unable to open time file: $db_script_path/backup/time.bak. Reason: $!");
$last_date = int <TIMEBAK>;
close TIMEBAK;
$date = time;
if ($date < $last_date + 86400) {
print "\tBackup exists for today.. Skipping\n";
return;
}
# Try to do it the right way..
eval { require File::Copy; };
if (!$@) {
print "\tBacking up links, category and email database (File::Copy) ... \n";
&File::Copy::copy ("$db_script_path/data/links.db", "$db_script_path/backup/links.db") or &cgierr ("Unable to copy links backup. Reason: $!");
&File::Copy::copy ("$db_script_path/data/categories.db", "$db_script_path/backup/categories.db") or &cgierr ("Unable to copy categories backup. Reason: $!");
&File::Copy::copy ("$db_script_path/data/email.db", "$db_script_path/backup/email.db") or &cgierr ("Unable to copy email backup. Reason: $!");
}
# Otherwise, the ugly way.
else {
print "\tBacking up links, category and email database (Regular - $@) ... \n";
foreach (qw!links categories email!) {
open (TMP, "$db_script_path/data/$_.db") or &cgierr ("Unable to open $db_script_path/data/$_.db. Reason: $!");
open (TMPOUT, ">$db_script_path/backup/$_.db") or &cgierr ("Unable to open $db_script_path/backup/$_.db. Reason: $!");
while (<TMP>) {
print TMPOUT;
}
close TMP;
close TMPOUT;
}
}
$date = time;
open (TIMEBAK, ">$db_script_path/backup/time.bak") or &cgierr("Unable to open time file: $db_script_path/backup/time.bak. Reason: $!");
if ($db_use_flock) { flock (TIMEBAK, 2) or &cgierr ("Unable to get exclusive lock on $db_script_path/backup/time.bak. Reason: $!"); }
print TIMEBAK $date;
close TIMEBAK;
}
# ***************************************** modification - end ******************