Re: Automated-backup script

From: Daniel Lidstrom (someone_at_microsoft.com)
Date: 05/11/04


Date: Tue, 11 May 2004 22:50:46 +0200

On Tue, 11 May 2004 20:20:35 +0000, Matt_left_coast wrote:

> 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.

Absolutely right...

>> 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 thank you for your patience.

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

Maybe I should stop doing backups for my friend. I asked him to use rsync
server, but he's not using it yet.

> 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

Thanks, this might be all the tips I need to do it myself.

> 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.

This is more than I asked for, but sure it would be nicer to have a date
and time in the filename.

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

I'm slowly getting a hang of it. Currently have scripts for writing cd's,
converting from dos to unix (remove ^M at end of lines), rip cd, train my
Othello program :-), convert mp3 to cdr, etc.

> '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.

Thank you very much!

-- 
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?


Relevant Pages

  • Re: Automated-backup script
    ... > 4) Compute checksums for both files. ... this group is not a script writing service. ... Make two directories: download and backup ...
    (alt.linux)
  • Re: Harry Potter All in one
    ... want to make a backup copy of it. ... You are NOT entitled to download a backup copy. ... Buying a dvd does not mean the movie belongs to you. ... to legitimatly buy as an e-book then they could frown upon people ...
    (alt.fan.harry-potter)
  • Re: Harry Potter All in one
    ... want to make a backup copy of it. ... Buying a dvd does not mean the movie belongs to you. ... Current law allows you to make a single copy for archival purposes, it does NOT allow you to download a copy from somewhere else. ... I have paid for it and I read it the way I chose to. ...
    (alt.fan.harry-potter)
  • Re: Harry Potter All in one
    ... want to make a backup copy of it. ... Buying a dvd does not mean the movie belongs to you. ... Current law allows you to make a single copy for archival purposes, it does NOT allow you to download a copy from somewhere else. ... However it is not in any companies interest to attack people that have already paid for their product but want it on a medium not offered by them. ...
    (alt.fan.harry-potter)
  • Re: WINLOGON.EXE
    ... Backup is a PC User's Best Friend ... >>download using that as this is a rather large download. ... >>you install updated drivers, ignore the message about ... >>Backup is a PC User's Best Friend ...
    (microsoft.public.windowsxp.general)