Beispiel #1
0
        private bool BackupDB(bool force = false)
        {
            string   backupFilepath;
            DateTime now = DateTime.UtcNow;

            if (!force && lastBackup.Date + maxDaysWithoutBackup >= now)
            {
                return(true);
            }

            backupFilepath = DBFile + ".backup";
            try {
                if (File.Exists(backupFilepath))
                {
                    File.Delete(backupFilepath);
                }

                File.Copy(DBFile, backupFilepath);
                Log.Debug("Created backup for database at ", backupFilepath);
                lastBackup = new BackupDate {
                    Date = now
                };
                UpdateBackupDate(false);
                return(true);
            } catch (Exception ex) {
                Log.Error("Could not create backup");
                Log.Exception(ex);
                return(false);
            }
        }
Beispiel #2
0
 private void GetBackupDate()
 {
     lastBackup = GetObject <BackupDate> ();
     if (lastBackup == null)
     {
         lastBackup = new BackupDate {
             Date = DateTime.UtcNow
         };
         UpdateBackupDate(true);
     }
     Log.Information("DB last backup: " + lastBackup.Date.ToShortDateString());
 }
Beispiel #3
0
        private void UpdateBackupDate(bool create)
        {
            IObjectContainer db = Db4oFactory.OpenFile(DBFile);

            try     {
                IQuery query = db.Query();
                query.Constrain(typeof(BackupDate));
                IObjectSet result = query.Execute();
                while (result.HasNext())
                {
                    BackupDate date = result.Next() as BackupDate;
                    db.Delete(date);
                }
                db.Store(lastBackup);
            } finally {
                db.Close();
            }
        }
Beispiel #4
0
        private void CreateNewDB()
        {
            // Create new DB and add version and last backup date
            IObjectContainer db = Db4oFactory.OpenFile(DBFile);

            try {
                dbVersion  = new Version(Constants.DB_MAYOR_VERSION, Constants.DB_MINOR_VERSION);
                lastBackup = new BackupDate {
                    Date = DateTime.UtcNow
                };
                db.Store(dbVersion);
                db.Store(lastBackup);
                Log.Information("Created new database:" + DBFile);
            }
            finally {
                db.Close();
            }
        }
Beispiel #5
0
        private void BackupDB()
        {
            string   backupFilepath;
            DateTime now = DateTime.UtcNow;

            if (lastBackup.Date + maxDaysWithoutBackup >= now)
            {
                return;
            }

            backupFilepath = Path.Combine(Config.DBDir(), backupFilename);
            if (File.Exists(backupFilepath))
            {
                File.Delete(backupFilepath);
            }

            File.Move(file, backupFilepath);
            Log.Information("Created backup for database at ", backupFilename);
            lastBackup = new BackupDate {
                Date = now
            };
            UpdateBackupDate();
        }