public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Volker Armin Hemmann <volkerarmin@googlemail.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Using date/time variables in cronjobs?
Date: Mon, 06 May 2013 02:09:57 +0200	[thread overview]
Message-ID: <5186F4D5.50904@googlemail.com> (raw)
In-Reply-To: <5186E96E.6020003@libertytrek.org>

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 <tanstaafl@libertytrek.org> 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.



  reply	other threads:[~2013-05-06  0:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-05 16:56 [gentoo-user] Using date/time variables in cronjobs? Tanstaafl
2013-05-05 17:07 ` Mick
2013-05-05 17:32   ` Tanstaafl
2013-05-05 17:49 ` Alan McKinnon
2013-05-05 18:07 ` Tanstaafl
2013-05-05 18:18   ` Neil Bothwick
2013-05-05 18:31   ` Tanstaafl
2013-05-05 20:06     ` Todd Goodman
2013-05-05 21:25       ` Neil Bothwick
2013-05-05 21:56         ` Tanstaafl
2013-05-05 23:21           ` Tanstaafl
2013-05-06  0:09             ` Volker Armin Hemmann [this message]
2013-05-06  9:48             ` Neil Bothwick
2013-05-06  3:25           ` Pandu Poluan
2013-05-11 16:51             ` SOLVED - WAS " Tanstaafl
2013-05-05 20:17     ` Alan McKinnon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5186F4D5.50904@googlemail.com \
    --to=volkerarmin@googlemail.com \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox