Created
August 18, 2012 22:58
-
-
Save hamstar/3390269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| $threshold = 60 | |
| $external_snapshots = "/media/external/snapshots" | |
| $system_snapshots = "/backup/backintime/AKSCOU01.local/root/1" | |
| # ensure correct drive is mounted | |
| # enforce the threshold | |
| freespace = `df -l|grep /media/external|tr -s ' ' ' '|cut -d' ' -f4`.chomp.to_i | |
| freespace = freespace / 1024 / 1024 | |
| if freespace < $threshold | |
| # email us | |
| puts "omg no space left!" | |
| end | |
| # get the latest external snapshot | |
| latest_external = Dir.entries( $external_snapshots ).sort_by{|name| | |
| File.stat("#{$external_snapshots}/#{name}").mtime | |
| }.delete_if {|n| n == "." || n == ".." }.last | |
| # get the latest system snapshot | |
| latest_system = Dir.entries( $system_snapshots ).sort_by{|name| | |
| File.stat("#{$system_snapshots}/#{name}").mtime | |
| }.delete_if {|n| n == "." || n == ".." }.last | |
| # copy the snapshot folder excluding the files subdir from system to external | |
| Dir.mkdir "#{$external_snapshots}/#{latest_system}" | |
| system "cp #{$system_snapshots}/#{latest_system}/* #{$external_snapshots}/#{latest_system}" | |
| # copy the files from the previous snapshot to the files subdir in the latest snapshot | |
| system "cp -lRf #{$external_snapshots}/#{latest_external}/backup #{$external_snapshots}/#{latest_system}" | |
| # rsync the latest files from the system files subdir to the latest external files subdir | |
| system "rsync -a #{$system_snapshots}/#{latest_system}/backup #{$external_snapshots}/#{latest_system}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment