scalingo_backups_manager 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/scalingo_backups_manager/cli.rb +21 -3
- data/lib/scalingo_backups_manager/sftp_tools.rb +16 -0
- data/lib/scalingo_backups_manager/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0ddc26bcd894cfe092ba3fbbcfa954c68661bf64639a88f224e99d8848de16e2
         | 
| 4 | 
            +
              data.tar.gz: 8742e9f0f1b4d3d2655a96f218eda3a753f13f4873440bb1e1e3c84ab7ba573c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 75f37abc3dc0c5fd0eb259d55d857cf79bdd402f2d653dae315822830a06f4dce895cdb686f74e845f806c3847a0606afa088ca0d279408002129c500186d276
         | 
| 7 | 
            +
              data.tar.gz: 58f6b07bbf870eff376e88c284e8dafa50eb5a0d95d28e685e2127de7544550ea2d81179214d0f031ad9002396237995db78afaa40162ffdace39ae42c3264e0
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -129,9 +129,11 @@ module ScalingoBackupsManager | |
| 129 129 | 
             
                  invoke :download, [], application: options[:application], addon: options[:addon]
         | 
| 130 130 | 
             
                  configuration = Configuration.new
         | 
| 131 131 | 
             
                  configuration.for_each_addons do |application, addon|
         | 
| 132 | 
            +
                    step = 1
         | 
| 132 133 | 
             
                    config = addon.sftp_config
         | 
| 133 134 | 
             
                    path = ("#{addon.config[:path]}" || "backups/#{addon.addon_provider[:id]}") + "/#{Time.now.strftime("%Y%m%d")}.tar.gz"
         | 
| 134 135 | 
             
                    next unless File.exists?(path)
         | 
| 136 | 
            +
                    puts "** Upload backup for #{application.name} **"
         | 
| 135 137 |  | 
| 136 138 | 
             
                    sftp = ScalingoBackupsManager::SftpTools.new(config[:auth])
         | 
| 137 139 |  | 
| @@ -148,16 +150,32 @@ module ScalingoBackupsManager | |
| 148 150 | 
             
                      next
         | 
| 149 151 | 
             
                    end
         | 
| 150 152 |  | 
| 151 | 
            -
                    config[:retention].each do |k,  | 
| 152 | 
            -
                       | 
| 153 | 
            -
                       | 
| 153 | 
            +
                    config[:retention].each do |k, retention_config|
         | 
| 154 | 
            +
                      retention_folders = folders.dup
         | 
| 155 | 
            +
                      retention_folders << config.dig(:retention, k, :dir)
         | 
| 156 | 
            +
                      remote_path = "/" + retention_folders.delete_if(&:blank?).join("/")
         | 
| 157 | 
            +
                      puts "#{step} - Creating remote directory at #{remote_path}"
         | 
| 158 | 
            +
                      step += 1
         | 
| 154 159 | 
             
                      sftp.mkdir!(remote_path)
         | 
| 155 160 | 
             
                      case k
         | 
| 156 161 | 
             
                      when "daily"
         | 
| 157 162 | 
             
                        sftp.upload_file(path, remote_path)
         | 
| 163 | 
            +
                        files = sftp.list_files(remote_path)
         | 
| 164 | 
            +
                        puts "#{step} - Checking daily backups"
         | 
| 165 | 
            +
                        step += 1
         | 
| 166 | 
            +
                        if files.size > retention_config[:ttl]
         | 
| 167 | 
            +
                          files_to_remove = files.sort_by(&:name).shift(files.size - retention_config[:ttl])
         | 
| 168 | 
            +
                          puts "#{step} - Removing #{files_to_remove.size} backups because of ttl configuration"
         | 
| 169 | 
            +
                          files_to_remove.each do |file|
         | 
| 170 | 
            +
                            puts "Removing file #{remote_path + "/" + file.name}"
         | 
| 171 | 
            +
                            sftp.remove!(remote_path + "/" + file.name)
         | 
| 172 | 
            +
                          end
         | 
| 173 | 
            +
                        end
         | 
| 158 174 | 
             
                      when "monthly"
         | 
| 159 175 | 
             
                        next unless Date.today.day == 1
         | 
| 160 176 | 
             
                        sftp.upload_file(path, remote_path)
         | 
| 177 | 
            +
                        puts "#{step} - Checking monthly backups"
         | 
| 178 | 
            +
                        step += 1
         | 
| 161 179 | 
             
                      end
         | 
| 162 180 | 
             
                    end
         | 
| 163 181 |  | 
| @@ -14,6 +14,22 @@ module ScalingoBackupsManager | |
| 14 14 | 
             
                  end
         | 
| 15 15 | 
             
                end
         | 
| 16 16 |  | 
| 17 | 
            +
                def list_files(path)
         | 
| 18 | 
            +
                  files = []
         | 
| 19 | 
            +
                  start do |sftp|
         | 
| 20 | 
            +
                    sftp.dir.glob("#{path}", "*.tar.gz").each do |file|
         | 
| 21 | 
            +
                      files << file
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                  files
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def remove!(path)
         | 
| 28 | 
            +
                  start do |sftp|
         | 
| 29 | 
            +
                    sftp.remove!(path)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 17 33 | 
             
                def mkdir!(path)
         | 
| 18 34 | 
             
                  start do |sftp|
         | 
| 19 35 | 
             
                    folder_tree = []
         |