Module: Kematzy::Tasks::Rake::DB

Defined in:
lib/kematzy/tasks.rb

Class Method Summary collapse

Class Method Details

.dump_all_dbs_and_wrap_dumps_with_comments(dump_dir = :backups) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: add some comments here

Examples



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kematzy/tasks.rb', line 21

def self.dump_all_dbs_and_wrap_dumps_with_comments(dump_dir = :backups) 
  # ensure we have that directory to dump into first
  FileUtils.mkdir_p("db/#{dump_dir.to_s}")
  
  Dir["db/*.db"].each do |db|
    if dump_dir == :bootstraps
      backup_file = "db/#{dump_dir}/#{File.basename(db)}.sql"
    else
      backup_file = "db/#{dump_dir}/#{Time.now.strftime("%Y%m%d-%H%M%S")}-#{File.basename(db)}.sql"
    end
    
    comment = %Q['-- ++++ ]
    if dump_dir == :bootstraps
      comment << %Q[\n-- BOOTSTRAP FILE FOR DB [ #{File.basename(db)} ] ]
    else
      comment << %Q[\n-- BACKUP OF DB [ #{File.basename(db)} ] ]
    end
    comment << %Q[\n-- IN APP [ #{Dir.pwd} ] ]
    comment << %Q[\n-- Created on [ #{Time.now.strftime("%Y-%m-%d at %H:%M:%S")} ] ]
    comment << %Q[\n-- ]
    comment << %Q[\n-- /++++ \n']
    
    `echo #{comment} > #{backup_file}`
    sh "sqlite3 #{db} .dump >> #{backup_file}"
    `echo '\n-- \n-- /EOF \n-- ' >> #{backup_file}`
  end
  
end