Skip to content

Instantly share code, notes, and snippets.

@Nama
Last active December 27, 2015 00:59
Show Gist options
  • Save Nama/7242107 to your computer and use it in GitHub Desktop.
Save Nama/7242107 to your computer and use it in GitHub Desktop.
Deleting of incoming and outdated SQL backups. Using with crontab.
#!/usr/bin/env python3
#Deleting of incoming and outdated SQL backups - Using with crontab
import os, re
d_list = sorted( #Filenames containing unix-timestamp, sorted() will set 'd_list' ordered, from old to new
re.findall(r'\w+\.sql\.gz', #searching for filenames
','.join(os.listdir('/home/kirika')))) #Listing all files in directory and putting them comma-seperated together
for i in range(len(d_list)-4): #Count of found files -4
os.remove(d_list[i]) #the newest 4 files wont be deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment