Results 1 to 9 of 9

Thread: Backup delete script

  1. #1
    Join Date
    May 2008
    Posts
    432
    Rep Power
    7

    Default Backup delete script

    Hello!
    For performance reasons, I do not want to use rsync with the --delete option to sync the /opt/zimbra/backup directory with our backup server.

    I am looking for a good, proven script that deletes all backups taht are, say, older than 21 days, and runs directly on the backup server.

    Do you have any good ones?

    Thanks

    Chris

  2. #2
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    could you do it simply with a find command? like

    Code:
    find /opt/zimbra/backup/sessions -depth 1 -ctime +21 -exec rm -rf {} \;
    this would basically find any directories in /opt/zimbra/backup/sessions that are over 21 days from creation and rm -rf them.

    anyone see why this wouldn't work?

  3. #3
    Join Date
    May 2008
    Posts
    432
    Rep Power
    7

    Default

    The thing is, I need it to be more clever than that, since this solution would delete, for example, the full backup of october 20th, and leave the incrementals of 21st, 22nd, etc. These are of no use without the underlying full backup, are they?

    Thanks

    Chris

  4. #4
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    yeah you're right the incrementals would be useless without the preceeding full.

  5. #5
    Join Date
    Feb 2007
    Location
    Portland, OR
    Posts
    1,147
    Rep Power
    10

    Default

    What backup script are you using? Without knowing the structure of your backups this would be rather hard to answer...

  6. #6
    Join Date
    May 2008
    Posts
    432
    Rep Power
    7

    Default

    Zimbra NE just uses the Network Edition Backup schedule, the backup directory is then rsynched to a remote server once a night.

  7. #7
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    7

    Default

    Here's a script I use for backing up stuff. Adjust the the number 21 to reflect however many files you'd like to keep. Of course, this is no good for incremental backups, only fulls.

    Code:
    #if the number of files in the backup folder is greater than or equal to 21
    if [ $(ls %YOUR DESTINATION DIRECTORY% | wc -l) -ge 21 ]
    then
            #navigate to backup directory
            cd %YOUR DESTINATION DIRECTORY%
            #remove the oldest file
            ls -1 -lt | awk ' /^-/ { print $9}' | tail -1 | xargs rm
            #create a new gzipped tar archive in the backup folder, using the current date in YYYY-MM-DD_24hr format as the filename.
            tar -czf %YOUR DESTINATION DIRECTORY%/$(date +%F)_$(date +%H%M).tar.gz %YOUR SOURCE DIRECTORY%
    else
            #create a new gzipped tar archive in the backup folder, using the current date in YYYY-MM-DD_24hr format as the filename.
            tar -czf %YOUR DESTINATION DIRECTORY%/$(date +%F)_$(date +%H%M).tar.gz %YOUR SOURCE DIRECTORY%
    fi
    - Joe

  8. #8
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    4

    Default

    Quote Originally Posted by iway View Post
    The thing is, I need it to be more clever than that, since this solution would delete, for example, the full backup of october 20th, and leave the incrementals of 21st, 22nd, etc. These are of no use without the underlying full backup, are they?

    Thanks

    Chris
    This script deletes all backups (full and incremental) except the last full
    and subsequent incrementals. It is not a perfect script (some incrementals
    remains) but it's all you can do with just two commands.

    #!/bin/sh
    BCKDIR="/opt/zimbra/backup/sessions"
    LIMIT=`ls -1drt $BCKDIR/full* | tail -2 | head -1`
    find $BCKDIR -maxdepth 1 -type d -not -newer $LIMIT -delete


    PS: i suggest you also to reprogram zimbra backup crontab
    using zmschedulebackup

  9. #9
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    5

    Default

    Why not grab a copy of the script zimbra uses, modify and run it on the remote server. Just make sure the backups are completing.

    /opt/zimbra/bin/zmbackup: perl script text executable

    Edit: nevermind, I did not realize the perl script is just a wrapper.
    Last edited by langseth; 10-20-2011 at 08:37 AM.

Similar Threads

  1. Replies: 658
    Last Post: 04-04-2014, 10:01 AM
  2. Tasks in ZD Beta 3
    By bjquinn in forum General Questions
    Replies: 6
    Last Post: 11-03-2008, 02:07 AM
  3. [SOLVED] Error running mailboxd after script backup
    By ttortosa in forum Administrators
    Replies: 5
    Last Post: 10-22-2008, 02:33 AM
  4. Zimbra Backup Script ... Small Problem
    By frankb in forum Administrators
    Replies: 12
    Last Post: 07-14-2008, 09:40 AM
  5. [SOLVED] Backups failing, "unable to read metadata for account"
    By smcgrath1111 in forum Administrators
    Replies: 10
    Last Post: 04-10-2008, 04:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •