Gossamer Forum
Home : Products : Links 2.0 : Customization :

Delete backup

Quote Reply
Delete backup
Hi Eliot, when I execute Build All or staggered a backup will be created.
25-May-2000.category.db
25-May-2000.email.db
25-May-2000.links.db

But it saves all the backups even if they are 3 weeks old. Do you have a code for me or do you know I can find this code that it will delete the backup files automatically when they are older then 5 days....

This code is to difficult for me...
Thanks again....

Quote Reply
Re: Delete backup In reply to
I use the following command line in my shell file that I use to re-build my index via Cron....

Code:

rm /path/to/cgi-bin/links/backups/*


If you want to keep a certain number of backup files in your backup directory, then you can do one or all of the following:

1) Use Widgetz's codes (posted in the Links Discussion Forum about four months ago) for creating a tar.gz file (compressed file), which will save disk space and also better organize your backup files.

2) Extract the codes out of these codes that will keep five days of backup files and then delete the rest.

So...search the Links Discussion Forum for Widgetz's code hack.

Regards,


Eliot Lee
Quote Reply
Re: Delete backup In reply to
Okay Eliot, found the posting at:
http://gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=L2Cust&Number=39470&page=&view=&sb=&part=all&vc=1

But there were a lot and I think this is the correct one.
(6th posting)

sub build_backup
{my $date = &get_date;my ($file, $saved, $deleted);
if (-e "$db_script_path/backup/$date.tar.gz") { print "\tBackup exists for today.. Skipping\n"; return; }
etc etc.....

this is a part of the code and I will use the good one from the link.
Eliot this code works under linux/unix??? but I'm working under WinNT and will use pkzip.exe. Can you help me how to modify this code...
Thanks again Eliot....

Quote Reply
Mod to save disk space [Re: Delete backup] In reply to
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 ******************
Quote Reply
Mod to save disk space [Re: Delete backup] In reply to
Another possibility is the -M filetest operator:
-M Age of file in days when script started.

Perl builtin functions: -X filetest operators
http://www.perl.com/...pod/perlfunc/_X.html

Anyway, with the file time.bak of the previous mod,
we can adjust the time more precisely.

Probably there are more possible solutions that
I haven't thought about, but the previous mod
to save disk space works fine.

Quote Reply
Mod to save disk space [Re: Delete backup] In reply to
Thanks for your contributions...

In Reply To:
Probably there are more possible solutions that
I haven't thought about, but the previous mod
to save disk space works fine.
There are...and were posted in the Links Discussion Forum as I previously mentioned.

Regards,

Eliot Lee
Quote Reply
Mod to save disk space [Re: Delete backup] In reply to
Thanks for all your help. The mod works perfect....

Quote Reply
Re: [Juan G] Mod seems NOT WORKING In reply to
 Server Error The following error occurred:

The server closed the connection while reading the response.

Is what i got after installing an empty time.bak file (done with notepad, CHMOD 644)

plus copy and paste the code on display here over the existing original sub_build_backup block.

What does the error message mean???

Is there simply a fault in the script mod or has it something to do with the time.bak file in the backup folder????



Heeeeeeeeeeeeeeeeeeelp, i really really wanna get rid of old backup automatically after every new "build" action (or after every new days build action, which ever applies.