require File.dirname(__FILE__) + '/spec_helper' describe "Postgres Backups" do before(:each) do @db_name = create_postgresql_database('first') end it "makes a custom format backup" do EY::Backup.run(["-c", backup_config_file, "-e", "postgresql"]) reset_logger EY::Backup.run(["-c", backup_config_file, "-l", @db_name, "-e", "postgresql"]) stdout.should match(/0:#{@db_name}.*\.dump$/) end it "makes a split backup" do EY::Backup.run(["-c", backup_config_file, "-e", "postgresql", "-s", "100"]) backup = EY::Backup.run(["-c", backup_config_file, "-e", "postgresql", "-l", @db_name]).first backup.parts.should > 1 end it "makes GPG encrypted backups" do import_gpg EY::Backup.run(["-c", backup_config_file, '-e', 'postgresql', '-k', Helpers::PUBLIC_KEY_ID]) EY::Backup.run(["-c", backup_config_file, '-e', 'postgresql', "-l", @db_name]) stdout.should match(/0:#{@db_name}/) end it "restores a backup" do run_psql("CREATE TABLE foo (id integer NOT NULL);", @db_name).should be_true run_psql("CREATE TABLE bar (id integer NOT NULL);", @db_name).should be_true EY::Backup.run(["-c", backup_config_file, '-e', 'postgresql']) run_psql("DROP TABLE bar;", @db_name).should be_true run_psql("SELECT * FROM bar;", @db_name).should be_false reset_logger EY::Backup.run(["-c", backup_config_file, "-l", @db_name, '-e', 'postgresql']) stdout.should include("1 backup(s) found") EY::Backup.run(["-c", backup_config_file, "-r", "0:#{@db_name}", '-e', 'postgresql']) run_psql("SELECT * FROM foo;", @db_name).should be_true run_psql("SELECT * FROM bar;", @db_name).should be_true end it "restores split backups" do run_psql("CREATE TABLE foo (id integer NOT NULL);", @db_name).should be_true run_psql("CREATE TABLE bar (id integer NOT NULL);", @db_name).should be_true EY::Backup.run(["-c", backup_config_file, "-e", "postgresql", "-s", "100"]) EY::Backup.run(["-c", backup_config_file, "-e", "postgresql", "-l", @db_name]).first.parts.should > 1 run_psql("DROP TABLE bar;", @db_name).should be_true run_psql("SELECT * FROM bar;", @db_name).should be_false EY::Backup.run(["-c", backup_config_file, "-l", @db_name, '-e', 'postgresql']) stdout.should include("1 backup(s) found") EY::Backup.run(["-c", backup_config_file, "-r", "0:#{@db_name}", '-e', 'postgresql']) run_psql("SELECT * FROM foo;", @db_name).should be_true run_psql("SELECT * FROM bar;", @db_name).should be_true end it "downloads a split backup to 1 file" do run_psql("CREATE TABLE foo (id integer NOT NULL);", @db_name).should be_true run_psql("CREATE TABLE bar (id integer NOT NULL);", @db_name).should be_true EY::Backup.run(["-c", backup_config_file, "-e", "postgresql", "-s", "100"]) EY::Backup.run(["-c", backup_config_file, "-e", "postgresql", "-l", @db_name]).first.parts.should > 1 EY::Backup.run(["-c", backup_config_file, "-e", 'postgresql', "--download", "0:#{@db_name}"]) files = Dir["#{EY::Backup.tmp_dir}/*#{@db_name}*"] files.size.should == 1 FileUtils.rm(files.first) end end describe "Postgresql Backups" do before(:each) do @dbs = [create_postgresql_database('first'), create_postgresql_database('second')] end it "makes multiple backup" do EY::Backup.run(["-c", backup_config_file, "-e", "postgresql"]) reset_logger @dbs.each do |db_name| EY::Backup.run(["-c", backup_config_file, "-l", db_name, '-e', 'postgresql']) stdout.should match(/0:#{db_name}/) end end end