RobbyAJM

Can't copy database.db file to database_backup

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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
On 11/3/2017 at 17:51, Ayush Rathore said:

tell me the position of database you want to backup

 

Original database in dayz/database.db 

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

Share this post


Link to post

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

Share this post


Link to post
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(...)

 

Share this post


Link to post
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

Share this post


Link to post

Actually, the first code already worked for me, so it'll be something else I think.

Share this post


Link to post
1 minute ago, NeXuS™ said:

Actually, the first code already worked for me, so it'll be something else I think.

well it also worked for me wait till the post owner reply :)

Share this post


Link to post

Solved, its working on Debian VPS

But doesnt work in Windows 7 ( tested in localhost server )

Thank you Ayush Rathore & Nexus :)

Share this post


Link to post
14 hours ago, RobbyAJM said:

Solved, its working on Debian VPS

But doesnt work in Windows 7 ( tested in localhost server )

Thank you Ayush Rathore & Nexus :)

you are welcome :)

 

Edited by Ayush Rathore

Share this post


Link to post

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.