Re: Automated-backup script

From: Matt_left_coast (not_at_chance.org)
Date: 05/11/04


Date: Tue, 11 May 2004 20:20:35 GMT

Daniel Lidstrom wrote:

> On Tue, 11 May 2004 16:23:58 +0000, Matt_left_coast wrote:
>
>> Daniel Lidstrom wrote:
>>
>>> Hi,
>>>
>>> I'm doing some backups for a friend. The script is placed in
>>> /etc/cron.daily and looks like this:
>>> #!/bin/bash
>>> wget http://www.sweden.se/ptk-src.tar.gz -P /backup/bobbo > /dev/null
>>> 2>&1
>>>
>>> This produces lots of ptk-src.tar.gz's in /backup/bobbo. I'd like to
>>> save only those that differ from previous versions. So, instead of
>>> having ptk-src.tar.gz.1, ptk-src.tar.gz.2, etc, that are all the same
>>> file, how can I save only the one that differs from previous? I don't
>>> mind the numbering, infact I think it is good.
>>>
>>> Thanks a lot!
>>>
>>
>> You could write a script that does a checksum then save only the ones
>> where the checksums differ.
>
> If I knew how to write that script, it would already be done :-)

Perhaps it is time to learn.

> My idea is the following:
> 1) download the backup file
> 2) find out what name it was given (by finding the latest modified file)
> 3) By name of file, I know what is the next-latest file (last
> character of file, if it is a digit, minus 1)
> 4) Compute checksums for both files.
> 5) If equal, remove latest file
> 6) Else, do nothing
>
> Anybody who is fluid with scripts that can help me?
> Thanks in advace.
>

The last I checked, this group is not a script writing service.

I would suggest you look into rsync over ssh rather than wget. If you insist
on wget, may I suggest you rethink the methodology?

Make two directories: download and backup
use wget to download all the files to download
then do a "for file in download/*; do" (examples are in your /etc/init.d
scripts) loop to compare the checksum of $file in download to the
$file.<timestamp> of the latest $file (an ls download/$file* piped to sort
piped to tail -1 will give you the latest file if you have the timestamp
done right) in backup to the files in backup, if they differ mv $file to
download/$file.<timestamp> else rm download/$file

You would want to make sure that download is cleared out before the loop is
started (rm -rf download/*). To do the time stamp use the date command to
set a variable:

timestamp=`date <format options you want>` before the loop. Then when you mv
the file it would be something like
mv download/$file backup/$file.$timestamp
if the checksums are different.

I'm not trying to be an ass, but I am trying to encourage you to learn
scripting for yourself.

'give a man a fish and you feed him for a day, teach him how to fish and you
feed him for life' sort of thinking.



Relevant Pages

  • Re: Automated-backup script
    ... >> 4) Compute checksums for both files. ... > use wget to download all the files to download ... > scripts) loop to compare the checksum of $file in download to the ... > done right) in backup to the files in backup, if they differ mv $file to ...
    (alt.linux)
  • Re: constant runtime errors-please help
    ... Common script errors messages can be eliminated by Clicking: ... click Internet Options. ... Two download versions are available for Windows Script 5.6. ... HiJackThis: - Free ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Idiot proof removal of junk?
    ... | I would like to send everyone a single script or small set of scripts ... | convince windows to boot into safe mode with command prompt. ... FireWall to allow it to download the needed AV vendor related files. ... This will bring up the initial menu of choices and should be executed in Normal Mode. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Foiling MITM attacks on source and ports trees
    ... Given read-only access to the repository, ... A script that has access to the Subversion repo would ... first in batch mode compute md5/sha256 checksums for *all* revisions ... and store them in the database as well. ...
    (freebsd-questions)
  • Announcement: Fix management tool for AIX 4.x/5.x available
    ... I'm pleased to announce a tool to automate download and management ... of ".bff" and ".rpm" fix packages for AIX ver. ... "fix-get.sh" script has been designed to automate fix packages ... discovery and download for servers with Unix AIX versions up to 5.3. ...
    (comp.unix.aix)