From owner-freebsd-questions@FreeBSD.ORG Mon May 20 13:53:23 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id AE9506C2 for ; Mon, 20 May 2013 13:53:23 +0000 (UTC) (envelope-from m@mbg.pt) Received: from mail-vb0-x234.google.com (mail-vb0-x234.google.com [IPv6:2607:f8b0:400c:c02::234]) by mx1.freebsd.org (Postfix) with ESMTP id 72FE4A92 for ; Mon, 20 May 2013 13:53:23 +0000 (UTC) Received: by mail-vb0-f52.google.com with SMTP id p13so3837535vbe.11 for ; Mon, 20 May 2013 06:53:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-originating-ip:in-reply-to:references :from:date:message-id:subject:to:cc:content-type:x-gm-message-state; bh=AZ8n5DxRxH+Ndvvx2NDqKB69WFBnYXFyQRuf5tDje9Y=; b=HIbbm+8T8+GGKvFo/Z/UIwU1ckloVzPTVhN4ZiaJxzDqMdM43zRfQLFqBeG83tfrT1 T2IYPrc9zM+du2/3o14MR8x/GBifHYnEM4ISvfXBgRcpVMJ/VxslMG5ekoSXBzKLroXm W8nW0ao16UpF+MV5znBM9YziRvTNQUDg4F9T0ISBUFhb6NkgWKF10rpcrXnrvW0gi+A8 pF3K/3vLYv2EGu9cj5r/5FLaIBbtBzDUG0K7GI3pzXef4NCg7/3e94XocpHx7jlzQ2eA rxpEOahd4HVjVXD3wad/FvuHqljy7t/lm80jCVfQO6NXUfWYzWhCsyrezzoi0q4Qi7Gg NM9A== X-Received: by 10.220.238.4 with SMTP id kq4mr9888102vcb.73.1369058002914; Mon, 20 May 2013 06:53:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.221.9.70 with HTTP; Mon, 20 May 2013 06:52:42 -0700 (PDT) X-Originating-IP: [213.228.167.112] In-Reply-To: <519A1843.3070808@eskk.nu> References: <519A1843.3070808@eskk.nu> From: =?ISO-8859-1?Q?Miguel_Barbosa_Gon=E7alves?= Date: Mon, 20 May 2013 14:52:42 +0100 Message-ID: Subject: Re: Delete files with time stamp on Samba Server To: Leslie Jensen X-Gm-Message-State: ALoCoQmfAEyUG+RybAAn+eN+62t1rDbvWXQtZyrRDvyS7Scti4G5TrmLiVs9n1jB8elh20uMsQBv Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: FreeBSD Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 May 2013 13:53:23 -0000 On 20 May 2013 13:34, Leslie Jensen wrote: > > I have a remote Samba Server where Windows machines place backup files > once a day. The format is > > > backup_2013-05-03_13.45.44_.**zip > > > Before the Windows client places the file it removes the file from the day > before. > > In turn I do a backup of the backup files once every week(Friday) to > another directory. > > This directory will eventually fill up and I need to make a check and > remove the oldest file maybe once a week before the new file is copied, or > put in other words I never want more than 4 files to be in this directory. > > My scripting skills are not at the level where I can figure this out, so > I'll appreciate suggestions on how to solve this in the correct way. > Hi Leslie! I believe this is what you need: --- START --- #!/bin/sh KEEP='5' pg_dump -U gp > /backups/gp.`date +%Y%m%d-%H%M%S`.sql N=1 for file in `ls -r /backups/gp.*` do [ $N -gt $KEEP ] && rm -f $file N=`expr $N + 1` done --- END --- I am using this to keep 5 backup files... Modify as needed. Cheers, Miguel