I have one requirement to replace device database with other db file, Its like taking backup and stored directory(download/backup/appname/) or server, if we delete data or if we lost phone then I have restore data from server and replace with device database file. I am trying with code but replacing database only I am not getting.
function doBackup(){
var defered = $.Deferred();
var version = parseFloat(window.device.version);
dbPath = cordova.file.applicationStorageDirectory
+'/app_webview/databases/file__0/1';
if(version < 4.4) {
dbPath = cordova.file.applicationStorageDirector+'/app_database
/file__0/0000000000000001.db';
}
var fileName = 'Backup_' + new Date().getTime();
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
fs.root.getDirectory(backupFolder, {
create : true,
exclusive : false
}, function(dir) {
window.resolveLocalFileSystemURL(dbPath, function(db) {
db.copyTo(dir, fileName, function() {
SaveBackupData(data, GetBackupData);
}, onfail)
});
}, onfail);
}, onfail);
function onfail(err){
return defered.reject(err);
}
return defered.promise();
}
For replacing database I am trying below code
function copyFileToDB(fName){
var defered = $.Deferred();
// request for file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs){
//request for directory Entry
var fileName = fName;
fs.root.getDirectory("Download/SMU/Backup/", {
create: false,
exclusive: false
}, function(destDirectoryEntry){
window.resolveLocalFileSystemURL(cordova.file.applicationStorageDirectory
+"app_webview/databases/file__0/1",function(fileEntry){
fileEntry.copyTo(destDirectoryEntry, fileEntry.name, function(){
alert("success - "+JSON.stringify(destDirectoryEntry));
}, onfail);
},onfail)
}, onfail);
}, onfail);
function onfail(err){
return defered.reject(err);
}
return defered.promise();
}
Pls anybody answer this question, I am have been trying this from one week But there is no luck and also not getting any suitable sources.. I need to replace device db file with another db file(which is already took backup for feature use). How the whatsapp stores and restore backup like that..
Anyhelp is much much appreciated.. Thanks in advance..