From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1NNGIK-000760-3c for garchives@archives.gentoo.org; Wed, 23 Dec 2009 01:45:44 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 46175E0760; Wed, 23 Dec 2009 01:45:09 +0000 (UTC) Received: from mail-pz0-f174.google.com (mail-pz0-f174.google.com [209.85.222.174]) by pigeon.gentoo.org (Postfix) with ESMTP id 14B71E0760 for ; Wed, 23 Dec 2009 01:45:09 +0000 (UTC) Received: by pzk4 with SMTP id 4so2417792pzk.32 for ; Tue, 22 Dec 2009 17:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=wh6QPIZY2cCEYZam/s6G+5Suo1iQ0ntdluQmCaORJP8=; b=TX2rXc+mMRF9x5l5Ba1fI8K5+bwZ8xxpDa+ijsYK4CiBevuGmC3vkzJV87gtWGuJmS zruM+rUYC+9DmFRdLOgffYTIPvDyh1gBmWvVQ+lt2PbIAcJvOgQfDHGL6eHXwnjD9e+E savrdhmZjUUbk96FhsXVJAsV6m5dMsVcAtmoU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=RcaSNxsiZKWq3u6NnosOdS6qjOTgU/A/qfe+iWN1UCCXzaLgtPTPi4U2szcKk/GnJU Vm1AxDgoMehy9GKu0oJ18G6PZ16QMOn+9D3zr8K1Vi8IFitiK8LANBnQRpqfgYcL/HKm 21mV8MNwJCQHsvLTr+zAbMnuWQww2nKWiSqXg= Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Received: by 10.115.102.16 with SMTP id e16mr6389874wam.202.1261532707975; Tue, 22 Dec 2009 17:45:07 -0800 (PST) In-Reply-To: <4B305492.3080302@gmail.com> References: <4B303B5D.2060400@gmail.com> <4B3052DB.7080809@ep.mine.nu> <4B305492.3080302@gmail.com> Date: Tue, 22 Dec 2009 23:45:07 -0200 Message-ID: <543f3b9c0912221745t1d9bb54cp5eee28aa7dbaf7e0@mail.gmail.com> Subject: Re: [gentoo-user] Writing a bash script or thinking about it anyway. From: Francisco Ares To: gentoo-user@lists.gentoo.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 85a59128-5f8d-4232-8cc1-b4245a388d51 X-Archives-Hash: 8672142e4d27b44997a1ab09e9b536d9 On Tue, Dec 22, 2009 at 3:09 AM, Dale wrote: > Neil Walker wrote: >> >> Dale wrote: >> >>> >>> Me again. =C2=A0I'm thinking about writing a bash script that backs up = my >>> /home directory. >>> >> >> I use a simple rsync cron job to backup entire servers every hour. Does >> the job for me. ;) >> >> >> Be lucky, >> >> Neil >> http://www.the-workathome.com >> >> > > But I wouldn't learn how to write a script that way. =C2=A0I got to start > somewhere. =C2=A0This is a good place. > > Dale > > :-) =C2=A0:-) > Now I got your point. I would think on something like this (untested): The command line would be BackupScriptName FromDirectory ToDirectory #! /bin/bash FROM=3D$1 TO=3D$2 cd $FROM for i in * .??* do if [[ -d "$i" ]] # is it a directory? then # yes, it is a directory if [[ -e "$TO/$i" ]] && [[ -d "$TO/$i" ]] then # on the TO side, the name exists # and it is a directory cd "$i" # just to show something pwd # calls recursively this same script $0 "$FROM/$i" "$TO/$i" cd .. else # didn't existed yet on the TO side, # so copy everything cp -a $FROM/$i $TO/$i fi else # it is a file, not a directory if [[ -e "$TO/$i" ]] then # the file already exists # do something to compare the files, like: # gets size from "ls" result SIZE1=3D`ls -l "$i" | cut -d" " -f5` SIZE2=3D`ls -l "TO/$i" | cut -d" " -f5 if (( $SIZE1!=3D$SIZE2 )) then # size is different, so copy the file cp -a "$FROM/$i" "$TO/$i" else # more tests for differences other # than size, like date/time # or even MD5SUM fi else # file doesn't exist at the "TO" side cp -a "$FROM/$i" "$TO/$i" fi fi done Hope this helps Francisco --=20 "If you have an apple and I have an apple and we exchange apples then you and I will still each have one apple. But if you have an idea and I have one idea and we exchange these ideas, then each of us will have two ideas." - George Bernard Shaw