opennebula-5.4.1-fixfederationimport.diff

Roy Keene, 10/11/2017 04:10 PM

Download (2.2 KB)

View differences:

opennebula-5.4.1-fixfederationimport/src/onedb/onedb_backend.rb 2017-10-11 01:06:51.920348848 -0500
203 203
            @block_n += 1
204 204
        end
205 205
    end
206

  
207
    def write_quotas(file)
208
        ["group_quotas", "user_quotas"].each do |table|
209
            file.puts "DELETE FROM #{table};"
210
        end
211
        @db.fetch("SELECT oid FROM user_pool;") { |row|
212
            file.puts "INSERT INTO user_quotas (user_oid, body) VALUES (#{row[:oid]}, \"<QUOTAS><ID>#{row[:oid]}</ID><DATASTORE_QUOTA></DATASTORE_QUOTA><NETWORK_QUOTA></NETWORK_QUOTA><VM_QUOTA></VM_QUOTA><IMAGE_QUOTA></IMAGE_QUOTA></QUOTAS>\");"
213
        }
214
        @db.fetch("SELECT oid FROM group_pool;") { |row|
215
            file.puts "INSERT INTO group_quotas (group_oid, body) VALUES (#{row[:oid]}, \"<QUOTAS><ID>#{row[:oid]}</ID><DATASTORE_QUOTA></DATASTORE_QUOTA><NETWORK_QUOTA></NETWORK_QUOTA><VM_QUOTA></VM_QUOTA><IMAGE_QUOTA></IMAGE_QUOTA></QUOTAS>\");"
216
        }
217
    end
206 218
end
207 219

  
208 220
class BackEndMySQL < OneDBBacKEnd
......
249 261
    end
250 262

  
251 263
    def backup(bck_file, federated = false)
264
        connect_db
265

  
252 266
        cmd = "mysqldump -u #{@user} -p'#{@passwd}' -h #{@server} " <<
253 267
              "-P #{@port} --add-drop-table #{@db_name} "
254 268

  
255 269
        cmd << FEDERATED_TABLES.join(" ") if federated
256 270

  
257
        cmd << " > #{bck_file}"
271
        cmd << " >> #{bck_file}"
272

  
273
        File.open(bck_file, "w") do |f|
274
            if federated
275
                write_quotas(f)
276
            end
277
        end
258 278

  
259 279
        rc = system(cmd)
260 280

  
......
336 356

  
337 357
    def backup(bck_file, federated = false)
338 358
        if federated
359
            connect_db
360

  
339 361
            puts "Sqlite database backup of federated tables stored in #{bck_file}"
340 362

  
341 363
            File.open(bck_file, "w") do |f|
......
343 365
                FEDERATED_TABLES.each do |table|
344 366
                    f.puts "DROP TABLE IF EXISTS \"#{table}\";"
345 367
                end
368
                write_quotas(f)
346 369
            end
347 370

  
348 371
            FEDERATED_TABLES.each do |table|