title: Delete old backup folders over lftp / ftp
body: <p>I'm writing a small backup script for my Ubuntu server. The files are tar'ed and zipped locally to a temporary folder, uploaded to the ftp server via lftp and finally deleted locally.</p>
  
  <p>Save files to the server:</p>
  
  <pre><code>FTPSUBDIR=`date --utc +"%Y-%m-%d"`
  echo "mkdir -p /daily/${FTPSUBDIR}; mirror --reverse ${TEMPDIR} /daily/${FTPSUBDIR};" | /usr/bin/lftp -u "$FTPUSER,$FTPPASS" "$FTPSERV"
  </code></pre>
  
  <p>The folder structure on the ftp server:</p>
  
  <pre><code>/
    daily
      2011-10-25
      2011-10-24
      2011-10-23
    weekly
      2011-10-23
      2011-10-16
      2011-10-09
  </code></pre>
  
  <p>How do I keep only the x newest backups(5 for daily, 4 for weekly) and delete the other folders on the ftp server? </p>