Exemplo n.º 1
0
def backup_php_site(server_name, site_name):
    """

    legalsecretaryjournal_com
    TODO Only really need to backup everything in the 'images' and 'sites'
    folder.
    """
    site_info = SiteInfo(server_name, site_name)
    backup_path = site_info.backup().get('path')
    print(green("Backup files on '{}'").format(env.host_string))
    path = Path(site_name, 'files')
    print(yellow(path.remote_folder()))
    run('mkdir -p {0}'.format(path.remote_folder()))
    # remove '.gz' from end of tar file
    #  tar_file = os.path.splitext(path.remote_file())[0]
    #  with cd('/home/legalsec/legalsecretaryjournal.com/'):
    #      first = True
    #      for folder in path.php_folders():
    #          if first:
    #              first = False
    #              run('tar cvf {} {}'.format(tar_file, folder))
    #          else:
    #              run('tar rvf {} {}'.format(tar_file, folder))
    #  run('gzip {}'.format(tar_file))
    #  # list the contents of the archive
    #  run('tar ztvf {}'.format(path.remote_file()))
    with cd(backup_path):
        run('tar -cvzf {} .'.format(path.remote_file()))
    get(path.remote_file(), path.local_file())
Exemplo n.º 2
0
def backup_ftp():
    if not env.site_info.is_ftp():
        abort("'{}' is not set-up for 'ftp'".format(env.site_info.site_name))
    print(green("Backup FTP files on '{}'").format(env.host_string))
    path = Path(env.site_info.site_name, 'ftp')
    run('mkdir -p {0}'.format(path.remote_folder()))
    with cd(path.ftp_folder(env.site_info.site_name)):
        run('tar -cvzf {} .'.format(path.remote_file()))
    get(path.remote_file(), path.local_file())
Exemplo n.º 3
0
def backup_files():
    """
    To backup the files 'rs.connexionsw' server:
    fab -H rs.web.connexionsw backup_files
    """
    print(green("Backup files on '{}'").format(env.host_string))
    name = env.host_string.replace('.', '_')
    name = name.replace('-', '_')
    path = Path(name, 'files')
    run('mkdir -p {0}'.format(path.remote_folder()))
    with cd(path.files_folder()), hide('stdout'):
        run('tar -czf {} .'.format(path.remote_file()))
    get(path.remote_file(), path.local_file())
Exemplo n.º 4
0
class TestPath(unittest.TestCase):

    def setUp(self):
        self.path = Path('csw_web', 'postgres')
        self.user = getpass.getuser()
        self.year = datetime.now().strftime('%Y')

    def test_backup_file_name(self):
        backup_file_name = self.path.backup_file_name()
        self.assertIn('csw_web_', backup_file_name)
        self.assertIn(self.user, backup_file_name)
        self.assertIn(self.year, backup_file_name)
        self.assertIn('sql', backup_file_name)

    def test_backup_file_name_postgres(self):
        backup_file_name = self.path.backup_file_name()
        self.assertIn('sql', backup_file_name)

    def test_backup_file_name_files(self):
        path = Path('csw_web', 'files')
        backup_file_name = path.backup_file_name()
        self.assertIn('tar.gz', backup_file_name)

    def test_backup_file_name_user(self):
        path = Path('raymond@csw_web', 'postgres')
        self.assertNotIn('raymond', path.backup_file_name())

    def test_database_name(self):
        database_name = self.path.database_name()
        self.assertNotIn('sql', database_name)

    def test_files_folder(self):
        self.assertEquals('/home/web/repo/files', self.path.files_folder())

    def test_invalid_name(self):
        with self.assertRaises(TaskError) as cm:
            Path('csw_web_*', 'postgres')
        self.assertIn('invalid characters', cm.exception.value)

    def test_invalid_file_type(self):
        with self.assertRaises(TaskError) as cm:
            Path('csw_web_', 'smartie')
        self.assertIn('invalid file type', cm.exception.value)

    def test_local_file_files(self):
        path = Path('csw_web', 'files')
        local_file = path.local_file()
        self.assertIn('/repo/backup/files/csw_web_', local_file)
        self.assertIn('.tar.gz', local_file)

    def test_local_file_postgres(self):
        local_file = self.path.local_file()
        self.assertIn('home', local_file)
        self.assertIn(self.user, local_file)
        self.assertIn('/repo/backup/postgres/csw_web_', local_file)
        self.assertIn('.sql', local_file)

    def test_remote_file_files(self):
        path = Path('csw_web', 'files')
        remote_file = path.remote_file()
        self.assertIn('/repo/backup/files/csw_web_', remote_file)
        self.assertIn('.tar.gz', remote_file)

    def test_remote_file_name_postgres(self):
        remote_file = self.path.remote_file()
        self.assertIn('/repo/backup/postgres/csw_web_', remote_file)
        self.assertIn('.sql', remote_file)

    def test_remote_folder_files(self):
        path = Path('csw_web', 'files')
        remote_folder = path.remote_folder()
        self.assertIn('/repo/backup/files', remote_folder)

    def test_remote_folder_postgres(self):
        remote_folder = self.path.remote_folder()
        self.assertIn('/repo/backup/postgres', remote_folder)

    def test_test_database_name(self):
        self.assertEquals(
            self.path.test_database_name(),
            'test_csw_web_{}'.format(getpass.getuser())
        )

    def test_user_name(self):
        self.assertEquals(self.path.user_name(), self.user)
Exemplo n.º 5
0
 def test_remote_folder_files(self):
     path = Path('csw_web', 'files')
     remote_folder = path.remote_folder()
     self.assertIn('/repo/backup/files', remote_folder)