title: Bash script to clean up old backup files
body: <p>I use a 12+31 backup system -- that is, I keep one file from each month for the past year, plus one file for each day of the current month. I'm having a hard time figuring out how to build a bash script that will do the following cleanup:</p>
  
  <ul>
  <li>search a directory and its subdirectories on a remote SFTP server</li>
  <li>in each directory, look for files that are: NOT from this month, AND not from the FIRST of the previous month</li>
  <li>with the selected files, delete them off the remote SFTP server</li>
  </ul>
  
  <p>For instance, if it is now November, this script would:</p>
  
  <ul>
  <li>search all the directories below a specified target, on my remote SFTP server</li>
  <li>ignore all the files that were created in November</li>
  <li>remove all the files from October EXCEPT for the files from October 1st</li>
  <li>remove all the files from September EXCEPT for the files from September 1st</li>
  <li>etc...</li>
  </ul>
  
  <p>This will be running on a shared hosting server (Dreamhost), so I won't have the ability to install any custom CLI tools.</p>
  
  <p>All of my backup files include the date in the filename, but I'd prefer to check against the file creation date if possible.</p>
  
  <p>I've seen a lot of stuff on deleting files older than [x], but I'm not at all clear how to skip over files that are from the first of the month.</p>