Revision 3a89a0d1

View differences:

src/onedb/onedb_backend.rb
232 232

  
233 233
    def bck_file
234 234
        t = Time.now
235
        "#{VAR_LOCATION}/mysql_#{@server}_#{@db_name}.sql_"<<
236
        "#{t.year}-#{t.month}-#{t.day}_#{t.hour}:#{t.min}:#{t.sec}.bck"
235
        "#{VAR_LOCATION}/mysql_#{@server}_#{@db_name}_"<<
236
        "#{t.year}-#{t.month}-#{t.day}_#{t.hour}:#{t.min}:#{t.sec}.sql"
237 237
    end
238 238

  
239 239
    def backup(bck_file)
240 240
        cmd = "mysqldump -u #{@user} -p'#{@passwd}' -h #{@server} " +
241
              "-P #{@port} #{@db_name} > #{bck_file}"
241
              "-P #{@port} --add-drop-table #{@db_name} > #{bck_file}"
242 242

  
243 243
        rc = system(cmd)
244 244
        if !rc
......
259 259
                  " use -f to overwrite."
260 260
        end
261 261

  
262
        mysql_cmd = "mysql -u #{@user} -p'#{@passwd}' -h #{@server} -P #{@port} "
263

  
264
        drop_cmd = mysql_cmd + "-e 'DROP DATABASE IF EXISTS #{@db_name};'"
265
        rc = system(drop_cmd)
266
        if !rc
267
            raise "Error dropping MySQL DB #{@db_name} at #{@server}."
268
        end
269

  
270
        create_cmd = mysql_cmd+"-e 'CREATE DATABASE IF NOT EXISTS #{@db_name};'"
271
        rc = system(create_cmd)
272
        if !rc
273
            raise "Error creating MySQL DB #{@db_name} at #{@server}."
274
        end
275

  
276
        restore_cmd = mysql_cmd + "#{@db_name} < #{bck_file}"
277
        rc = system(restore_cmd)
262
        rc = system("mysql -u #{@user} -p'#{@passwd}' -h #{@server} -P #{@port} #{@db_name} < #{bck_file}")
278 263
        if !rc
279 264
            raise "Error while restoring MySQL DB #{@db_name} at #{@server}."
280 265
        end

Also available in: Unified diff