Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#!/usr/bin/ruby # --------------------------------------------------------------------- # MySQL Backup Utility # Usage: ./mysql_backup.rb or ruby mysql_backup.rb # --------------------------------------------------------------------- $backup_archive = true # gzip files after processing $backup_dir = "/home/storage/backup/" # output directory $backup_template = "project-%s-%s.sql" # text-%dbname-%timestamp.sql $backup_cmd = "mysqldump -u local_backup --add-drop-table --databases %s > %s" # command to backup $backup_dblist = [ # list of databases to backup 'main', 'users', 'admin', 'cards' ] def backup_database(database) time = Time.now() time_str = sprintf("%02i-%02i-%04i-%02i%02i%02i",time.day,time.month,time.year,time.hour,time.min,time.sec) filename = sprintf($backup_template,database,time_str) filename = "#{$backup_dir}#{filename}" cmd = sprintf($backup_cmd,database,filename) if system(cmd) then system("gzip --best #{filename}") if $backup_archive end end $backup_dblist.each do |db| puts "Processing database... #{db}" backup_database(db) end
This paste will be private.
From the Design Piracy series on my blog: