From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 36F8E1381F3 for ; Mon, 6 May 2013 00:10:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 394D6E096C; Mon, 6 May 2013 00:10:02 +0000 (UTC) Received: from mail-bk0-f45.google.com (mail-bk0-f45.google.com [209.85.214.45]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D4764E08E2 for ; Mon, 6 May 2013 00:10:00 +0000 (UTC) Received: by mail-bk0-f45.google.com with SMTP id je9so1337303bkc.4 for ; Sun, 05 May 2013 17:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=7m76fTuFYbxHDlWBbFqIZaPGjrxuUbwLqEQ4e8VwkI4=; b=i1kjkDbbC7lfg+/wZECc9D/WJmeau76Fa8hl9UC5MYXk254MHGd6Z028yknBaqpdoi HaLxS2Z45ak/gX+zc45+enLjIRCt1DoNwj66dTn35YPFmz6QK92QF4rbKvxldGcMksBi 9RGcVaHWh+CJ+GxSq5drjg/g5KuU4914dlbtjQABE3IMiOMGzB27ni3rUuVgbFlV0eiH mMyfAKlTdYuF5qL2ZPNecowp4OpMnY+EWxFevema81NpCg7juRAuHkA5FeBuDtOPk3qf Z25lLiiDhUUgQWQtjzhXLX5LJIbw/WmMbJXrhLgPVLjLlMPYrUmoTe1S4SNlNV0Uy0Q2 I2sA== X-Received: by 10.205.128.68 with SMTP id hd4mr7589574bkc.23.1367798998897; Sun, 05 May 2013 17:09:58 -0700 (PDT) Received: from [192.168.178.21] (p57A85FC0.dip0.t-ipconnect.de. [87.168.95.192]) by mx.google.com with ESMTPSA id f14sm4748359bky.16.2013.05.05.17.09.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 17:09:58 -0700 (PDT) Message-ID: <5186F4D5.50904@googlemail.com> Date: Mon, 06 May 2013 02:09:57 +0200 From: Volker Armin Hemmann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130427 Thunderbird/17.0.5 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 To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] Using date/time variables in cronjobs? References: <51868F41.6050407@libertytrek.org> <51869FF6.3000308@libertytrek.org> <5186A58C.4070804@libertytrek.org> <20130505200645.GK29733@ns1.bonedaddy.net> <20130505222531.5cf1612b@digimed.co.uk> <5186D580.8070607@libertytrek.org> <5186E96E.6020003@libertytrek.org> In-Reply-To: <5186E96E.6020003@libertytrek.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Archives-Salt: 2a5d9283-fac4-4a31-a643-614b2ce1434d X-Archives-Hash: 85e94e909fbbb9a9d1fb91c2c0534bf6 Am 06.05.2013 01:21, schrieb Tanstaafl: > Last question... > > In order to keep only a certain number of backups, what would be the > easiest and SAFEST way to delete the older ones? > > For example, I want to keep 17 hourlies, and 30 nightlies, so I have > two cron jobs set up, the hourly, and the nightly. Each backs up to a > separate dir. > > I'm thinking the easiest way would be to find and delete the oldest > file in the backup target directory before executing the backup command. > > For the hourlies dir, I'd just find the files that are older than one > day - so maybe: > > find $BACKUP_DIR/hourly* -type f -mtime +1 -delete > > Would that do it? > > So, in my script, I could add this in like: > > #!/bin/bash > BACKUP_DIR="/home/user/mypg_backups/hourly" > PGUSER="superuser" > PGyy=`date '+%Y'` > PGmm=`date '+%m'` > PGdd=`date '+%d_'` > PGtt=`date '+%H:%M'` > find $BACKUP_DIR* -type f -mtime +1 -delete > /usr/bin/pg_dumpall -U $PGUSER -o -f > $BACKUP_DIR/mypg-$PGyy-$PGmm-$PGdd$PGtt.gz > > and for the nightly backup script, since I want to keep 30 days worth: > > #!/bin/bash > BACKUP_DIR="/home/user/mypg_backups/nightly" > PGUSER="superuser" > PGyy=`date '+%Y'` > PGmm=`date '+%m'` > PGdd=`date '+%d_'` > PGtt=`date '+%H:%M'` > find $BACKUP_DIR* -type f -mtime +30 -delete > /usr/bin/pg_dumpall -U $PGUSER -o -f > $BACKUP_DIR/mypg-$PGyy-$PGmm-$PGdd$PGtt.gz > > Am I asking for trouble doing it this way? > > On 2013-05-05 5:56 PM, Tanstaafl wrote: >> So, my final script looks like this: >> >> #!/bin/bash >> BACKUP_DIR="/home/user/mypg_backups" >> PGUSER="superuser" >> PGyy=`date '+%Y'` >> PGmm=`date '+%m'` >> PGdd=`date '+%d_'` >> PGtt=`date '+%H:%M'` >> /usr/bin/pg_dumpall -U $PGUSER -o -f >> $BACKUP_DIR/mypg-$PGyy-$PGmm-$PGdd$PGtt.gz >> >> For some reason, if I put the underscore in the filename itself, ie: >> >> $BACKUP_DIR/mypg-$PGyy-$PGmm-$PGdd_$PGtt.gz >> >> It omitted the $PGdd variable entirely. >> >> I had to add the underscore into the variable to get the output like I >> wanted. Weird... >> >> Anyway, this is working perfectly, thanks guys. >> > > > and then your backup scripts fails without you noticing and you just removed all your backups. oops.