Commit 6d56b233 authored by Xavier Thompson's avatar Xavier Thompson

software/theia: Fix export and import script

The import script was overwriting the contents of ~/etc
which destroyed all the services running in the clone,
including the ones that allow the PBS to push new backup files.
parent 20f59e7a
...@@ -35,15 +35,15 @@ md5sum = d78a9f885bdebf6720197209e0c21aa0 ...@@ -35,15 +35,15 @@ md5sum = d78a9f885bdebf6720197209e0c21aa0
[theia-common] [theia-common]
_update_hash_filename_ = theia_common.py _update_hash_filename_ = theia_common.py
md5sum = e57396473b4b6a17d26a747f0030293c md5sum = 38eba0fb605953677b5a2a2e686a66a2
[theia-export] [theia-export]
_update_hash_filename_ = theia_export.py _update_hash_filename_ = theia_export.py
md5sum = b5f5ac1924b27d3f2be2e5ea291c119e md5sum = d338b2d3ba1dcd7a919c0baf51dd11da
[theia-import] [theia-import]
_update_hash_filename_ = theia_import.py _update_hash_filename_ = theia_import.py
md5sum = 9e8c17a4b2d802695caf0c2c052f0d11 md5sum = 3580f1eec1099bebd550ba1eacd9c116
[yarn.lock] [yarn.lock]
_update_hash_filename_ = yarn.lock _update_hash_filename_ = yarn.lock
......
...@@ -4,6 +4,7 @@ import glob ...@@ -4,6 +4,7 @@ import glob
import hashlib import hashlib
import os import os
import re import re
import shutil
import subprocess as sp import subprocess as sp
import sqlite3 import sqlite3
...@@ -21,13 +22,19 @@ EXCLUDE_FLAGS = ['--exclude={}'.format(x) for x in sorted(EXCLUDE_PATTERNS)] ...@@ -21,13 +22,19 @@ EXCLUDE_FLAGS = ['--exclude={}'.format(x) for x in sorted(EXCLUDE_PATTERNS)]
def makedirs(path): def makedirs(path):
try: try:
os.makedirs(path if os.path.isdir(path) else os.path.dirname(path)) os.makedirs(path)
except OSError as e: except OSError as e:
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST:
raise raise
def copytree(rsyncbin, src, dst, exclude=[], extrargs=[], verbosity='-v'): def copyfile(src, dst):
dst = os.path.abspath(dst)
makedirs(os.path.dirname(dst))
shutil.copy2(src, dst)
def copytree(rsyncbin, src, dst, exclude=(), extrargs=(), verbosity='-v'):
# Ensure there is a trailing slash in the source directory # Ensure there is a trailing slash in the source directory
# to avoid creating an additional directory level at the destination # to avoid creating an additional directory level at the destination
src = os.path.join(src, '') src = os.path.join(src, '')
...@@ -60,15 +67,15 @@ def copytree(rsyncbin, src, dst, exclude=[], extrargs=[], verbosity='-v'): ...@@ -60,15 +67,15 @@ def copytree(rsyncbin, src, dst, exclude=[], extrargs=[], verbosity='-v'):
def copydb(sqlite3bin, src_db, dst_db): def copydb(sqlite3bin, src_db, dst_db):
makedirs(dst_db) makedirs(os.path.dirname(dst_db))
sp.check_output((sqlite3bin, src_db, '.backup ' + dst_db)) sp.check_output((sqlite3bin, src_db, '.backup ' + dst_db))
def remove(path): def remove(path):
try: try:
os.remove(path) os.remove(path)
except OSError: except OSError as e:
if os.path.exists(path): if e.errno != errno.ENOENT:
raise raise
......
...@@ -9,8 +9,8 @@ import traceback ...@@ -9,8 +9,8 @@ import traceback
import six import six
from six.moves import configparser from six.moves import configparser
sys.path.append(os.path.dirname(__file__)) sys.path.insert(0, os.path.dirname(__file__))
from theia_common import copytree, copydb, hashwalk, parse_installed, remove from theia_common import *
os.environ['LC_ALL'] = 'C' os.environ['LC_ALL'] = 'C'
...@@ -59,10 +59,14 @@ class TheiaExport(object): ...@@ -59,10 +59,14 @@ class TheiaExport(object):
return os.path.abspath(os.path.join( return os.path.abspath(os.path.join(
self.backup_dir, os.path.relpath(src, start=self.root_dir))) self.backup_dir, os.path.relpath(src, start=self.root_dir)))
def backuptree(self, src, exclude=[], extrargs=[], verbosity='-v'): def backuptree(self, src, exclude=(), extrargs=(), verbosity='-v'):
dst = self.mirrorpath(src) dst = self.mirrorpath(src)
return copytree(self.rsync_bin, src, dst, exclude, extrargs, verbosity) return copytree(self.rsync_bin, src, dst, exclude, extrargs, verbosity)
def backupfile(self, src):
dst = self.mirrorpath(src)
return copyfile(src, dst)
def backupdb(self): def backupdb(self):
copydb(self.sqlite3_bin, self.proxy_db, self.mirrorpath(self.proxy_db)) copydb(self.sqlite3_bin, self.proxy_db, self.mirrorpath(self.proxy_db))
...@@ -118,12 +122,12 @@ class TheiaExport(object): ...@@ -118,12 +122,12 @@ class TheiaExport(object):
def export(self): def export(self):
export_start_date = int(time.time()) export_start_date = int(time.time())
etc_dir = os.path.join(self.root_dir, 'etc') timestamp = os.path.join(self.root_dir, 'etc', '.resilient_timestamp')
with open(os.path.join(etc_dir, '.resilient_timestamp'), 'w') as f: with open(timestamp, 'w') as f:
f.write(str(export_start_date)) f.write(str(export_start_date))
self.loginfo('Backup directory ' + etc_dir) self.loginfo('Backup resilient timestamp ' + timestamp)
self.backuptree(etc_dir, extrargs=('--filter=- */', '--filter=-! .*')) self.backupfile(timestamp)
for d in self.dirs: for d in self.dirs:
self.loginfo('Backup directory ' + d) self.loginfo('Backup directory ' + d)
......
...@@ -10,7 +10,7 @@ import six ...@@ -10,7 +10,7 @@ import six
from six.moves import configparser from six.moves import configparser
sys.path.append(os.path.dirname(__file__)) sys.path.append(os.path.dirname(__file__))
from theia_common import copytree, copydb, hashwalk, parse_installed, remove from theia_common import *
os.environ['LC_ALL'] = 'C' os.environ['LC_ALL'] = 'C'
...@@ -70,10 +70,14 @@ class TheiaImport(object): ...@@ -70,10 +70,14 @@ class TheiaImport(object):
return os.path.abspath(os.path.join( return os.path.abspath(os.path.join(
self.root_dir, os.path.relpath(src, start=self.backup_dir))) self.root_dir, os.path.relpath(src, start=self.backup_dir)))
def restoretree(self, dst, exclude=[], extrargs=[], verbosity='-v'): def restoretree(self, dst, exclude=(), extrargs=(), verbosity='-v'):
src = self.mirrorpath(dst) src = self.mirrorpath(dst)
return copytree(self.rsync_bin, src, dst, exclude, extrargs, verbosity) return copytree(self.rsync_bin, src, dst, exclude, extrargs, verbosity)
def restorefile(self, dst):
src = self.mirrorpath(dst)
return copyfile(src, dst)
def restoredb(self): def restoredb(self):
copydb(self.sqlite3_bin, self.mirrorpath(self.proxy_db), self.proxy_db) copydb(self.sqlite3_bin, self.mirrorpath(self.proxy_db), self.proxy_db)
...@@ -157,9 +161,9 @@ class TheiaImport(object): ...@@ -157,9 +161,9 @@ class TheiaImport(object):
self.loginfo('Restore slapproxy database') self.loginfo('Restore slapproxy database')
self.restoredb() self.restoredb()
etc_dir = os.path.join(self.root_dir, 'etc') timestamp = os.path.join(self.root_dir, 'etc', '.resilient_timestamp')
self.loginfo('Restore directory ' + etc_dir) self.loginfo('Restore resilient timestamp ' + timestamp)
self.restoretree(etc_dir, extrargs=('--filter=- */', '--filter=-! .*')) self.restorefile(timestamp)
custom_script = os.path.join(self.root_dir, 'srv', 'runner-import-restore') custom_script = os.path.join(self.root_dir, 'srv', 'runner-import-restore')
if os.path.exists(custom_script): if os.path.exists(custom_script):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment