Jump to content

Can't copy database.db file to database_backup


RobbyAJM

Recommended Posts

Anyone can help me ? error in while backup database.db and copying file towards 'database_backup' folder

Console output:

[2017-03-11 15:47:55] WARNING: [mod]\dayz\login.lua:813: Operation failed @ 'fileCopy' [Unable to copy database.db to database_backup/11.3.2017_15.47.55_K05XBrN100.db]

Here's function inside login.lua

function baseCopy()
    local randomName = randomString(10)
    local time = getRealTime()
    local second = time.second
    local minute = time.minute
    local hour = time.hour
    local monthday = time.monthday
    local month = time.month
    local year = time.year
    fileCopy("database.db","database_backup/"..monthday.."."..month + 1 ..".".. year + 1900 .."_"..hour.."."..minute.."."..second.."_"..randomName..".db")
end

Thanks.

Link to comment
function baseCopy()
    local randomName = randomString(10)
    local time = getRealTime()
    local second = time.second
    local minute = time.minute
    local hour = time.hour
    local monthday = time.monthday
    local month = time.month
    local year = time.year
    local res = getResourceName(getThisResource())
    local pathtocopy = ":"..res.."/".."database_backup/"..monthday.."."..month + 1 ..".".. year + 1900 .."_"..hour.."."..minute.."."..second.."_"..randomName..".db"
    fileCopy("database.db",pathtocopy)
end

Try This

Link to comment
22 minutes ago, Ayush Rathore said:

function baseCopy()
    local randomName = randomString(10)
    local time = getRealTime()
    local second = time.second
    local minute = time.minute
    local hour = time.hour
    local monthday = time.monthday
    local month = time.month
    local year = time.year
    local res = getResourceName(getThisResource())
    local pathtocopy = ":"..res.."/".."database_backup/"..monthday.."."..month + 1 ..".".. year + 1900 .."_"..hour.."."..minute.."."..second.."_"..randomName..".db"
    fileCopy("database.db",pathtocopy)
end

Try This

Thank you Ayush, i'll test it and i'll back on a minutes.

 

EDIT: DOESNT Solved :(

22 minutes ago, Ayush Rathore said:

function baseCopy()
    local randomName = randomString(10)
    local time = getRealTime()
    local second = time.second
    local minute = time.minute
    local hour = time.hour
    local monthday = time.monthday
    local month = time.month
    local year = time.year
    local res = getResourceName(getThisResource())
    local pathtocopy = ":"..res.."/".."database_backup/"..monthday.."."..month + 1 ..".".. year + 1900 .."_"..hour.."."..minute.."."..second.."_"..randomName..".db"
    fileCopy("database.db",pathtocopy)
end

Try This

Doesnt work, output on the console is same within the first post

Edited by RobbyAJM
Link to comment
1 hour ago, NeXuS™ said:

I think it cannot be copied because the file is in use.

Me too. You should disconnect it.

 

if database then
  destroyElement(database) or mysql_close(database)
end


-- for after file copying
database = dbConnect(...) or mysql_connect(...)

 

Link to comment
9 hours ago, NeXuS™ said:

I think it cannot be copied because the file is in use.

 

7 hours ago, ZoRRoM said:

Me too. You should disconnect it.

 


if database then
  destroyElement(database) or mysql_close(database)
end


-- for after file copying
database = dbConnect(...) or mysql_connect(...)

 

well it does not matter the file is being used or not you cannot delete but u can copy, Think of it as coping a gta.exe when its running :) but you cannot delete it

9 hours ago, RobbyAJM said:

Original database in dayz/database.db 

I want to copy the database automatic by console to dayz/database_backup/ but its doesnt work

local bsaved = false
local timer = nil
function baseCopy()
    local randomName = ""
    local time = getRealTime()
    local second = time.second
    local minute = time.minute
    local hour = time.hour
    local monthday = time.monthday
    local month = time.month
    local year = time.year
    local res = getResourceName(getThisResource())
    local pathtocopy = ":dayz/database_backup/"..monthday.."."..month + 1 ..".".. year + 1900 .."_"..hour.."."..minute.."."..second.."_"..randomName..".db"
    if fileCopy(":dayz/database.db",pathtocopy) then
    outputDebugString("database saved")
    end
end
addCommandHandler("backupmydata",basecopy)

function checkforNoPlayers()
  if getPlayerCount() == 0 and bsaved == false then
  baseCopy()
  bsaved = true
  killTimer(timer)
  end
end

addEventHandler("onResourceStart",root,function(res)
if res == getThisResource() then
timer = setTimer(checkforNoPlayers,1000,0)
outputDebugString("timer for saving created")
end
end)

addEventHandler("onPlayerJoin",root,function() 
if isTimer(timer) then
outputDebugString("timer for saving already exists")
else
bsaved = false
timer = setTimer(checkforNoPlayers,1000,0)      
outputDebugString("timer for saving created")
end
end)

well you should use it when all the players are disconnected as it would lead to data loss if you copy while player is playing as query could be running :)

use this above code of mine it will automatically save you data when a player count = 0 and if you want it to be forced use /backupmydata in console

Edited by Ayush Rathore
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...