Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Manage backups #57

Merged
merged 23 commits into from
Nov 2, 2017
Merged

Manage backups #57

merged 23 commits into from
Nov 2, 2017

Conversation

GregLeBarbar
Copy link
Contributor

@GregLeBarbar GregLeBarbar commented Oct 29, 2017

From issue: #53

high level:

  1. new commands backup and backup-many to backup one single site or all sites in source of trust.

     $ python jahia2wp.py backup $WP_ENV http://localhost
     ...
     $ python jahia2wp.py backup-many path/to/csv
     ...
    
  2. Backups are full by default, but can be incremental by using option --backup-type

     $ python jahia2wp.py backup $WP_ENV http://localhost --backup-type=inc
     ...
    
  3. new environment variable BACKUP_PATH to define where to store backups (by default: jahia2wp/data/backups)

low level:

A backup of a WordPress site relies on a WPConfig, and is called/used in a similar way as WPGenerator. It creates three files:

  • a .tar of all WP files (php, assets, media)
  • a .list reference file for incremental backups
  • a .sql dump of the database

Backups are stored in BACKUP_PATH (by default: jahia2wp/data/backups), with the following name convention: <wp_site_name>[_<timestamp>]_fullN[_incM].<tar|list|sql>

DISCLAIMER: next iteration might revise this structure for something more easily exploitable, such as:

backups
├── site_1
│   ├── 2017-10-31
│   │   ├── full-201710310945.tar
│   │   ├── inc-201711012300.tar
│   │   ├── inc-201711022301.tar
│   │   └── inc-201711032310.tar
│   └── 2017-11-06
│       └── full-201711060946.tar
├── site_2
│   └── 2017-11-06
│       ├── full-201711060947.tar
│       └── inc-201711060946.tar
└── site_3

def __init__(self, openshift_env, wp_site_url, wp_default_site_title=None):
def __init__(self, openshift_env, wp_site_id, wp_site_url, wp_default_site_title=None):

self. wp_site_id = wp_site_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y'a un espace de trop là non ?

@@ -65,8 +65,8 @@ def keep_wp_sites(dir_name):
yield WPResult(wp_config.wp_site.path, "KO", "", "", "", "", "")

def run_wp_cli(self, command):
cmd = "wp {} --path='{}'".format(command, self.wp_site.path)
return Utils.run_command(cmd)
WPUtils.run_wp_cli(command, self.wp_site.path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faudrait faire un return WPUtils.run_wp_cli(command, sefl.wp_site_path)

Parce que là, tu exécutes 2x la commande, une fois en l'appelant via WPUtils.run_wp_cli et une fois via return Utils.run_command. Quoique le 2e appel sera probablement foireux car il n'y a pas de notion de "path".

else:
self.dir_name = self.wp_site.folder.split("/")[-1]

# Create a backup folder data/backups/wp_site_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Détail mais en lisant le commentaire, j'ai compris que la commande créait le dossier de backup... alors que c'est juste le chemin jusqu'à celui-ci qui est généré. La création du dossier en elle-même est faite plus tard

@GregLeBarbar
Copy link
Contributor Author

GregLeBarbar commented Oct 30, 2017 via email

@GregLeBarbar
Copy link
Contributor Author

GregLeBarbar commented Oct 30, 2017 via email

@GregLeBarbar
Copy link
Contributor Author

GregLeBarbar commented Oct 30, 2017 via email

@GregLeBarbar
Copy link
Contributor Author

GregLeBarbar commented Oct 30, 2017 via email

@LuluTchab
Copy link
Collaborator

LuluTchab commented Oct 30, 2017

J'ai regardé pourquoi les checks Travis ne passaient pas et y'a encore plein de choses à modifier pour que "wp_site_id" soit pris en compte partout... y compris modifier les tests Travis.
Ceci est notifié dans la description de la PR mais si on veut merge et que tout continue à fonctionner, autant adapter aussi le reste du code.
Je m'en occupe

@codecov
Copy link

codecov bot commented Oct 30, 2017

Codecov Report

Merging #57 into master will increase coverage by 0.7%.
The diff coverage is 87.33%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #57     +/-   ##
=========================================
+ Coverage   82.88%   83.59%   +0.7%     
=========================================
  Files          20       21      +1     
  Lines        1221     1359    +138     
=========================================
+ Hits         1012     1136    +124     
- Misses        209      223     +14
Impacted Files Coverage Δ
src/wordpress/__init__.py 100% <100%> (ø) ⬆️
src/tests/test_jahia2wp.py 98.07% <100%> (+0.25%) ⬆️
src/veritas/tests/test_veritas.py 100% <100%> (ø) ⬆️
src/veritas/validators.py 96.96% <100%> (+0.19%) ⬆️
src/utils.py 96.55% <100%> (+0.12%) ⬆️
src/settings.py 100% <100%> (ø) ⬆️
src/veritas/veritas.py 100% <100%> (ø) ⬆️
src/wordpress/tests/test_wordpress.py 100% <100%> (ø) ⬆️
src/wordpress/themes.py 85% <100%> (ø) ⬆️
src/jahia2wp.py 74.73% <53.33%> (+0.02%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06c27dd...9993734. Read the comment docs.

@LuluTchab
Copy link
Collaborator

Tests Travis fonctionnels après modifications 😀

@ebreton
Copy link
Contributor

ebreton commented Oct 31, 2017

Après discussion avec @lboatto et @LuluTchab , j'ai "annulé" les 5 derniers commits qui introduisaient le wp_site_id

git reset --soft HEAD~5
git push -f origin feature-wwp-53-backup

src/jahia2wp.py Outdated
jahia2wp.py admins <wp_env> <wp_site_id> <wp_url> [--debug | --quiet]
jahia2wp.py check-one <wp_env> <wp_site_id> <wp_url> [--debug | --quiet] [DEPRECATED]
jahia2wp.py clean-one <wp_env> <wp_site_id> <wp_url> [--debug | --quiet] [DEPRECATED]
jahia2wp.py generate-one <wp_env> <wp_site_id> <wp_url> [--debug | --quiet] [DEPRECATED]
[--wp-title=<WP_TITLE> --admin-password=<ADMIN_PASSWORD>]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A priori pas nécessaire de passer le wp_site_id de la sorte.
Complique l'utilisation de la CLI.
On devrait viser la simplification (par ex enlever wp_env 😏 )

# /srv/test/localhost/htdocs/;KO;;;;;
# /srv/test/localhost/htdocs/unittest;ok;http://localhost/unittest;4.8;wp_"""
# assert Utils.run_command('python %s inventory %s /srv/test/localhost'
# % (SCRIPT_FILE, TEST_ENV)).startswith(expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi commenter ?

src/utils.py Outdated
backup_listed_incremental_file,
source_path
)
logging.debug("Command to generate tar file: {}".format(command))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à priori déjà loggué dans run_command (ligne suivante)

src/utils.py Outdated
backup_listed_incremental_file,
source_path
)
logging.debug("Command to generate tar file: {}".format(command))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si jamais, les fonctions de log ne doivent pas utilser format, mais passer les arguments de formatage en argument de fonction:

logging.debug("Command to generate tar file: %s", command)

# ",".join([wp_user.username for wp_user in wp_config.admins]),
# )
# else:
# yield WPResult(wp_config.wp_site.path, "KO", "", "", "", "", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi commenter ?

Backup types:
There are 2 types of backup :
- full : Full backup.
- inc : Incremental backup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

préciser qu'il s'agit juste des fichiers

A backup of a WordPress site contains :
- copy of all .php file (tar files)
- a dump of the database (.sql file)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

préciser qu'on a les médias

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

et les assets :)

The content difference between incremental tar files are saved in the list file.
"""

BACKUP_ROOT_DIR = "../data/backups/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pas une bonne idée les chemins relatifs dans le code



class WPBackup:
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On propose une autre façon de structurer les fichiers:

backups
├── site_id_1
│   ├── 2017-10-31
│   │   ├── full-2017-10-31-09-45.tar
│   │   ├── inc-2017-11-01-23-00.tar
│   │   ├── inc-2017-11-02-23-01.tar
│   │   └── inc-2017-11-03-23-10.tar
│   └── 2017-11-06
│       └── full-2017-11-06-09-46.tar
├── site_id_2
│   └── 2017-11-06
│       ├── full-2017-11-06-09-47.tar
│       └── inc-2017-11-06-09-46.tar
└── site_id_3

Ca évite d'utiliser des numéros (et de les maintenir/générer) et ca simplifie l'exploitation/maintenance

from utils import Utils


class WPBackup:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs tests

ebreton and others added 3 commits October 31, 2017 23:27
* origin: (33 commits)
  added doc
  moved WPTheme/PluginConfig to dedicated files themes/plugin.py
  Use var defined in 'settings.py' instead of hard-coded string
  Use site folder as 'wp_site_id'
  Small bug fix
  Change way to generate path, add var for plugin source
  Change function/option name
  Use wp_site_id instead of site_name (which is not unique)
  Use WPSite to create instance instead of openshift_env and wp_site_url
  Small bug fix
  Workaround for relative path to fix Travis checks
  Change how class is displayed
  Change display way
  PEP8 compliant
  Add short doc (very short)
  Add feature to dump plugin configuration
  Updated configuration for Add-To-Any, fits to new way to do things
  Change WP tables infos location (now outside class), prepare to use 'wp site id' instead of 'wp site name', PEP8
  Use values defined in 'settings.py' and some cosmetic changes
  Replace way to configure plugin options. No more WPCLI...
  ...
@ebreton ebreton merged commit 3120798 into master Nov 2, 2017
@ebreton ebreton deleted the feature-wwp-53-backup branch November 6, 2017 07:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants