Module: BackupCleaner::Cli

Defined in:
lib/backup_cleaner/cli.rb

Class Method Summary collapse

Class Method Details

.run ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/backup_cleaner/cli.rb', line 6

def self.run
  opts = Trollop::options do
    banner "Cleans up backup files or folders within the specified folder. The names of these files/folders must include the backup date \\\nin a format like: YYYY-MM-DD. Any files/folders with names not matching this pattern will be left untouched. Between \\\ntoday and <days> days ago, all backups will be kept. Between today and <weeks> weeks ago, weekly backups will be kept. For \\\nall time, monthly backups will be kept. For weekly/monthly backups, the earliest available backup from the week/month will \\\nbe kept. For example, if daily backups are present then weekly backups will be from Sunday and monthly backups will be from \\\nthe 1st of the month.\n\nThis script can also handle backups from multiple projects in one directory as long as they are named differently. If files \\\nnamed aaa-2010-01-01.tar.gz and 2010-01-01.bbb.tar.bz2 exist then both will be kept. When comparing the names, only letters \\\nare considered. For example, aaa-2010-01-01.tar.gz and aaa-2010-01-01.12.12.12.tar.gz.2 are considered to be from the same \\\nbackup project and unless these backups are from the last <days> days, one will be deleted.\n\nUsage:\n  clean_backups.rb [options] <folder>\n\nwhere [options] are:\n  EOS\n\n    opt :days, \"Number of days for which to keep daily backups\", :type => :int, :default => 14\n    opt :weeks, \"Number of weeks for which to keep weekly backups\", :type => :int, :default => 8\n    opt :dry_run, \"Don't really delete anything, just print out what would have been deleted\", :short => :n\n  end\n\n  folder = ARGV.shift\n  Trollop::die \"No folder specified\" unless folder\n\n  # clean the backups\n  BackupCleaner.clean_backups(folder, opts)\nend\n"