MediaWikiServerTools 0.2.3__tar.gz → 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/PKG-INFO +3 -2
  2. mediawikiservertools-0.2.7/mwstools_backend/__init__.py +1 -0
  3. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/cron_backup.py +77 -17
  4. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/remote.py +22 -2
  5. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/sql_backup.py +7 -2
  6. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/tsite.py +14 -4
  7. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/version.py +1 -1
  8. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/pyproject.toml +3 -0
  9. mediawikiservertools-0.2.3/mwstools_backend/__init__.py +0 -1
  10. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/.github/workflows/build.yml +0 -0
  11. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/.github/workflows/upload-to-pypi.yml +0 -0
  12. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/.gitignore +0 -0
  13. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/.project +0 -0
  14. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/.pydevproject +0 -0
  15. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/AGENTS.md +0 -0
  16. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/LICENSE +0 -0
  17. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/README.md +0 -0
  18. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/html_table.py +0 -0
  19. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/server.py +0 -0
  20. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/site.py +0 -0
  21. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/webscrape.py +0 -0
  22. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/mwstools_backend/wikibackup.py +0 -0
  23. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/scripts/blackisort +0 -0
  24. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/scripts/doc +0 -0
  25. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/scripts/install +0 -0
  26. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/scripts/release +0 -0
  27. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/scripts/test +0 -0
  28. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/__init__.py +0 -0
  29. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/smw_access.py +0 -0
  30. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/test_remote.py +0 -0
  31. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/test_server.py +0 -0
  32. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/test_site.py +0 -0
  33. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/test_sqlbackup.py +0 -0
  34. {mediawikiservertools-0.2.3 → mediawikiservertools-0.2.7}/tests/test_wikibackup.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: MediaWikiServerTools
3
- Version: 0.2.3
3
+ Version: 0.2.7
4
4
  Summary: MediaWikiServerTools: MediaWiki Server Management System
5
5
  Project-URL: Home, https://github.com/BITPlan/MediaWikiServerTools
6
6
  Project-URL: Source, https://github.com/BITPlan/MediaWikiServerTools
@@ -22,6 +22,7 @@ Requires-Dist: beautifulsoup4>=4.9.3
22
22
  Requires-Dist: lxml
23
23
  Requires-Dist: py-3rdparty-mediawiki>=0.19.4
24
24
  Requires-Dist: pybasemkit>=0.2.4
25
+ Requires-Dist: pyexpirebackups>=0.1.3
25
26
  Requires-Dist: pymogwai>=0.1.1
26
27
  Requires-Dist: pymysql>=1.1.1
27
28
  Provides-Extra: test
@@ -0,0 +1 @@
1
+ __version__ = "0.2.7"
@@ -32,6 +32,7 @@ class CronBackup(BaseCmd):
32
32
  """
33
33
  super().__init__(version)
34
34
  self.backup_dir = None
35
+ self.archive_dir = None
35
36
  self.log_file = None
36
37
  self.container = None
37
38
  self.full_backup = False
@@ -71,7 +72,13 @@ class CronBackup(BaseCmd):
71
72
  parser.add_argument(
72
73
  "--backup-dir",
73
74
  default="/var/backup/sqlbackup",
74
- help="backup directory path [default: %(default)s]",
75
+ help="local backup directory (today/ + tmp/ dumps) [default: %(default)s]",
76
+ )
77
+ parser.add_argument(
78
+ "--archive-dir",
79
+ default=None,
80
+ help="directory for the dated .tgz archive + expiration; may be a "
81
+ "remote/mounted path (defaults to --backup-dir)",
75
82
  )
76
83
  parser.add_argument(
77
84
  "--log-file",
@@ -79,7 +86,24 @@ class CronBackup(BaseCmd):
79
86
  help="log file path [default: %(default)s]",
80
87
  )
81
88
  # database settings
82
- # the database container running the mysql instance
89
+ # backend selection: native client vs docker container
90
+ parser.add_argument(
91
+ "--native",
92
+ action="store_true",
93
+ help="use the native MySQL/MariaDB client (sudo mysql / sudo mysqldump -u root) "
94
+ "instead of a docker container",
95
+ )
96
+ parser.add_argument(
97
+ "--docker",
98
+ metavar="CN",
99
+ help="use the docker container CN (via the mysqlr wrapper) for MySQL access",
100
+ )
101
+ parser.add_argument(
102
+ "--backup-user",
103
+ default="backup",
104
+ help="OS user that owns the backup files [default: %(default)s]",
105
+ )
106
+ # the database container running the mysql instance (legacy; prefer --docker CN)
83
107
  parser.add_argument(
84
108
  "--container",
85
109
  default="family-db",
@@ -125,6 +149,14 @@ class CronBackup(BaseCmd):
125
149
  help="number of yearly backups to keep [default: %(default)s]",
126
150
  )
127
151
 
152
+ # per-command timeout for the dumps (large DBs need far more than 10s)
153
+ parser.add_argument(
154
+ "--timeout",
155
+ type=float,
156
+ default=3600,
157
+ help="timeout in seconds for each SQL dump/command [default: %(default)s]",
158
+ )
159
+
128
160
  # Shell configuration
129
161
  parser.add_argument(
130
162
  "--profile", help="shell profile to source (e.g., ~/.zprofile)"
@@ -173,7 +205,7 @@ class CronBackup(BaseCmd):
173
205
  )
174
206
 
175
207
  expire_backups = ExpireBackups(
176
- rootPath=str(self.backup_dir),
208
+ rootPath=str(self.archive_dir),
177
209
  baseName="sql_backup",
178
210
  ext=".tgz",
179
211
  expiration=expiration,
@@ -186,6 +218,7 @@ class CronBackup(BaseCmd):
186
218
  self.log("Expiration rules completed")
187
219
 
188
220
  except Exception as ex:
221
+ self.log(f"ERROR: {type(ex).__name__}: {ex}")
189
222
  self.handle_exception(ex)
190
223
  exit_code = 1
191
224
 
@@ -201,7 +234,8 @@ class CronBackup(BaseCmd):
201
234
  exit_code = 1
202
235
  date_str = datetime.now().strftime("%Y-%m-%d")
203
236
  archive_name = f"sql_backup.{date_str}.tgz"
204
- archive_path = self.backup_dir / archive_name
237
+ self.archive_dir.mkdir(parents=True, exist_ok=True)
238
+ archive_path = self.archive_dir / archive_name
205
239
 
206
240
  self.log(f"Creating archive {archive_name}...")
207
241
 
@@ -234,7 +268,15 @@ class CronBackup(BaseCmd):
234
268
  )
235
269
 
236
270
  cmd = " ".join(cmd_parts)
237
- result = self.shell.run(cmd, text=True, debug=self.debug, tee=self.verbose)
271
+ # honour --timeout: the basemkit Shell.run default of 60 s truncates
272
+ # large archives (see issue #11 / the qn 2026-07-01 incident)
273
+ result = self.shell.run(
274
+ cmd,
275
+ text=True,
276
+ debug=self.debug,
277
+ tee=self.verbose,
278
+ timeout=self.args.timeout,
279
+ )
238
280
 
239
281
  if result.returncode == 0:
240
282
  self.log(f"Archive {archive_name} created successfully")
@@ -245,6 +287,7 @@ class CronBackup(BaseCmd):
245
287
  exit_code = 1
246
288
 
247
289
  except Exception as ex:
290
+ self.log(f"ERROR: {type(ex).__name__}: {ex}")
248
291
  self.handle_exception(ex)
249
292
  exit_code = 1
250
293
 
@@ -264,19 +307,26 @@ class CronBackup(BaseCmd):
264
307
  # Ensure backup directory exists
265
308
  self.backup_dir.mkdir(parents=True, exist_ok=True)
266
309
 
267
- # Construct MySQL commands
268
- mysql_root_cmd = self.args.mysql_root_cmd
269
- if mysql_root_cmd is None:
270
- # Default: use mysqlr wrapper with container
271
- mysql_root_cmd = f"mysqlr --no-tty -cn {self.container}"
310
+ # Construct MySQL commands.
311
+ # Explicit --mysql-root-cmd / --mysqldump-cmd always win; otherwise the
312
+ # backend is chosen by --native (native client) vs docker container
313
+ # (--docker CN, falling back to the legacy --container default).
314
+ if self.args.native:
315
+ default_root_cmd = "sudo mysql"
316
+ default_dump_cmd = "sudo mysqldump -u root"
317
+ else:
318
+ cn = self.args.docker or self.container
319
+ default_root_cmd = f"mysqlr --no-tty -cn {cn}"
320
+ default_dump_cmd = f"mysqlr --no-tty -cn {cn} --dump"
272
321
 
273
- mysqldump_cmd = self.args.mysqldump_cmd
274
- if mysqldump_cmd is None:
275
- mysqldump_cmd = f"mysqlr --no-tty -cn {self.container} --dump"
322
+ mysql_root_cmd = self.args.mysql_root_cmd or default_root_cmd
323
+ mysqldump_cmd = self.args.mysqldump_cmd or default_dump_cmd
324
+ self.log(f"MySQL root cmd: {mysql_root_cmd}")
325
+ self.log(f"mysqldump cmd: {mysqldump_cmd}")
276
326
 
277
327
  # Create SqlBackup instance
278
328
  sql_backup = SqlBackup(
279
- backup_user="backup",
329
+ backup_user=self.args.backup_user,
280
330
  backup_host="localhost",
281
331
  backup_dir=str(self.backup_dir),
282
332
  mysql_root_script=mysql_root_cmd,
@@ -284,6 +334,7 @@ class CronBackup(BaseCmd):
284
334
  verbose=self.verbose,
285
335
  debug=self.debug,
286
336
  progress=self.args.progress,
337
+ timeout=self.args.timeout,
287
338
  )
288
339
 
289
340
  # Initialize if needed
@@ -303,6 +354,7 @@ class CronBackup(BaseCmd):
303
354
  exit_code = 1
304
355
 
305
356
  except Exception as ex:
357
+ self.log(f"ERROR: {type(ex).__name__}: {ex}")
306
358
  self.handle_exception(ex)
307
359
  exit_code = 1
308
360
 
@@ -330,6 +382,9 @@ class CronBackup(BaseCmd):
330
382
 
331
383
  # Store configuration
332
384
  self.backup_dir = Path(args.backup_dir)
385
+ self.archive_dir = (
386
+ Path(args.archive_dir) if args.archive_dir else self.backup_dir
387
+ )
333
388
  self.log_file = Path(args.log_file)
334
389
  self.container = args.container
335
390
  self.full_backup = args.full
@@ -357,6 +412,11 @@ class CronBackup(BaseCmd):
357
412
  self.exit_code = result
358
413
 
359
414
  handled = True
415
+ # BaseCmd.run() never reads self.exit_code and would exit 0 even
416
+ # after a failed backup (issue #11) — propagate via SystemExit,
417
+ # which BaseCmd.handle_exception maps to the process exit code.
418
+ if self.exit_code != 0:
419
+ raise SystemExit(self.exit_code)
360
420
 
361
421
  return handled
362
422
 
@@ -375,12 +435,12 @@ def main(argv=None):
375
435
  # Create a version object
376
436
  class Version:
377
437
  name = "CronBackup"
378
- version = "0.1.1"
438
+ version = "0.2.7"
379
439
  description = (
380
440
  "Database backup with expiration management to be started from cron"
381
441
  )
382
- updated = "2025-12-23"
383
- doc_url = "https://github.com/WolfgangFahl/pyWikiCMS"
442
+ updated = "2026-07-05"
443
+ doc_url = "https://github.com/WolfgangFahl/MediaWikiServerTools"
384
444
 
385
445
  exit_code = CronBackup.main(Version(), argv)
386
446
  return exit_code
@@ -547,11 +547,24 @@ class Remote:
547
547
  self.log.log("✅", "sync", f"{marker_path} already exists")
548
548
  return subprocess.CompletedProcess([], 0, "", "")
549
549
  proc = self.prepare_target_directory(target_path, run_config)
550
+ if proc.returncode == 0 and run_config.should_set_permissions:
551
+ # make the existing target tree group-writable BEFORE rsync so the
552
+ # rsync receiver (running as a www-data group member) can create its
553
+ # temp files in pre-existing images/* subdirs (closes #9).
554
+ # g+rwX adds execute only on directories, leaving files non-executable.
555
+ target_on_host = self.get_path_on_target(target_path)
556
+ if self.get_file_stats(target_on_host) is not None:
557
+ pre_perm_cmds = {
558
+ "chown_tree": f"sudo chown -R {run_config.uid}:{run_config.gid} {target_path}",
559
+ "chmod_tree": f"sudo chmod -R g+rwX {target_path}",
560
+ }
561
+ proc = self.run_cmds_as_single_cmd(pre_perm_cmds)
550
562
  if proc.returncode == 0:
551
563
  timeout = run_config.timeout if run_config else 30
552
564
  rsync_cmd = (
553
565
  f"rsync -avz --no-perms --omit-dir-times --timeout={timeout} {source_path}/* {target_path}"
554
566
  )
567
+ print(f"⚙️ {rsync_cmd}")
555
568
  proc = self.run(rsync_cmd, run_config=run_config)
556
569
 
557
570
  if run_config.should_set_permissions and proc.returncode == 0:
@@ -564,8 +577,15 @@ class Remote:
564
577
  if proc.returncode == 0:
565
578
  self.run(f"touch {marker_path}")
566
579
 
567
- status = "✅" if proc.returncode == 0 else "❌"
568
- self.log.log(status, "sync", f"synching {message}")
580
+ success = proc.returncode == 0
581
+ status = "✅" if success else "❌"
582
+ message = f"synching {message}"
583
+ if not success:
584
+ # surface the real rsync error instead of swallowing it (closes #8)
585
+ message += (
586
+ f" failed (rc={proc.returncode})\n{proc.stdout}\n{proc.stderr}"
587
+ )
588
+ self.log.log(status, "sync", message)
569
589
 
570
590
  return proc
571
591
 
@@ -16,7 +16,7 @@ from typing import List
16
16
  from basemkit.persistent_log import Log
17
17
  from tqdm import tqdm
18
18
 
19
- from mwstools_backend.remote import Remote
19
+ from mwstools_backend.remote import Remote, RunConfig
20
20
 
21
21
 
22
22
  class SqlBackup:
@@ -34,6 +34,7 @@ class SqlBackup:
34
34
  verbose: bool = False,
35
35
  debug: bool = False,
36
36
  progress: bool = False,
37
+ timeout: float = 3600,
37
38
  ):
38
39
  """
39
40
  Initialize SQLBackup instance
@@ -57,7 +58,10 @@ class SqlBackup:
57
58
  self.verbose = verbose
58
59
  self.debug = debug
59
60
  self.progress = progress
60
- self.remote = Remote(host=backup_host)
61
+ # SQL dumps of large DBs need far more than the RunConfig 10s default;
62
+ # honour a configurable timeout on every remote command (default 1h).
63
+ self.timeout = timeout
64
+ self.remote = Remote(host=backup_host, run_config=RunConfig(timeout=timeout))
61
65
  self.today_dir = self.backup_dir / "today"
62
66
  self.tmp_dir = self.backup_dir / "tmp"
63
67
 
@@ -313,6 +317,7 @@ class SqlBackup:
313
317
  """
314
318
  cmds = {
315
319
  "create temp dir": f"sudo mkdir -p {self.tmp_dir}",
320
+ "create today dir": f"sudo mkdir -p {self.today_dir}",
316
321
  "change permissions": f"sudo chmod 777 {self.tmp_dir}",
317
322
  "change owner": f"sudo chown {self.backup_user} {self.tmp_dir}",
318
323
  }
@@ -5,6 +5,8 @@ Tools to transfer a mediawiki site from one server to another
5
5
  to e.g. migrate the LAMP stack elements or move from a farm based
6
6
  to a dockerized environment
7
7
 
8
+ see also https://www.semantic-mediawiki.org/wiki/SMWCon_Fall_2020/Mediawiki_1.35_Migration
9
+
8
10
  @author: wf
9
11
  """
10
12
 
@@ -198,6 +200,7 @@ class TransferTask:
198
200
  uid=33, # www-data
199
201
  gid=33, # www-data
200
202
  )
203
+ rsync_prof = Profiler("rsync sync", profile=self.args.profile)
201
204
  proc = self.target.remote.rsync(
202
205
  source_path=source_path,
203
206
  target_path=site_path,
@@ -205,13 +208,20 @@ class TransferTask:
205
208
  message=f"{self.wiki_site.hostname}",
206
209
  run_config=run_config,
207
210
  )
208
- if proc.returncode == 0:
209
- print("✅ sync done")
210
- result = True
211
+ if proc.returncode != 0:
212
+ # abort on rsync failure - do not proceed to git (closes #8)
213
+ print(
214
+ f"❌ rsync sync {self.wiki_site.hostname} failed"
215
+ f" (rc={proc.returncode})\n{proc.stdout}\n{proc.stderr}"
216
+ )
217
+ return False
218
+ rsync_prof.time(f" {self.wiki_site.hostname}")
219
+ result = True
211
220
  if self.use_git:
221
+ git_prof = Profiler("git commit", profile=self.args.profile)
212
222
  proc = self.git_target(target_path=site_path)
213
223
  if proc.returncode == 0:
214
- print("✅ git committed")
224
+ git_prof.time(f" {self.wiki_site.hostname}")
215
225
  else:
216
226
  result = False
217
227
  return result
@@ -18,7 +18,7 @@ class Version(object):
18
18
  description = "MediaWiki Server Management System - Apache Site management, SQL backups, cron-based backups "
19
19
  version = mwstools_backend.__version__
20
20
  date = "2022-11-16"
21
- updated = "2026-06-07"
21
+ updated = "2026-06-10"
22
22
  authors = "Wolfgang Fahl"
23
23
  doc_url = "https://wiki.bitplan.com/index.php/MediaWikiServerTools"
24
24
  chat_url = "https://github.com/WolfgangFahl/MediaWikiServerTools/discussions"
@@ -30,6 +30,9 @@ dependencies = [
30
30
  'PyMySQL>=1.1.1',
31
31
  # https://pypi.org/project/pyMogwai/
32
32
  "pyMogwai>=0.1.1",
33
+ # https://pypi.org/project/pyExpireBackups/
34
+ # provides the `expirebackups` module imported by mwstools_backend.cron_backup (issue #10)
35
+ "pyExpireBackups>=0.1.3",
33
36
  ]
34
37
 
35
38
  requires-python = ">=3.10"
@@ -1 +0,0 @@
1
- __version__ = "0.2.3"