Skip to content

Commit

Permalink
bump v0.5.0
Browse files Browse the repository at this point in the history
- new command: version
- fix: wildcard symbol '*' conflicts with shell's
  • Loading branch information
Grvzard committed Feb 20, 2024
1 parent 2e6864f commit fe0d790
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#### From pypi
```
pip install ibdx
or
pipx install ibdx (recommended)
```

#### From source
Expand All @@ -20,14 +22,6 @@ cd ibdx
pip install .
```

#### Edit config
```
cp demo.env .env
vim .env
```
the .env works only when the ```ibdx``` command is running in that directory


## Usage

```ibdx --help```
Expand All @@ -43,10 +37,10 @@ Let's say we have following tables:
```[ logs_2023_01, logs_2023_02, logs_2023_03, logs_2023_04 ]```

```
ibdx backup --db test1 --tables logs_2023_* -f logs.2023.zip [--datadir /mysql/datadir]
ibdx backup -u user -p password -h localhost --db test1 --tables logs_2023_% -f logs.2023.zip [--datadir /mysql/datadir]
```
```
ibdx restore -f logs.2023.zip --db test1 --tables logs_2023_* [--datadir /mysql/datadir]
ibdx restore -f logs.2023.zip -u user -p password -h localhost --db test1 --tables logs_2023_% [--datadir /mysql/datadir]
```

When the mysql server is running in Docker, the _--datadir_ option is required.
Expand Down
2 changes: 1 addition & 1 deletion ibdx/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.4.0'
__version__ = '0.5.0'
6 changes: 6 additions & 0 deletions ibdx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typer
import logging

from ibdx import __version__
from ibdx.ibd_backup import ibd_backup
from ibdx.ibd_restore import ibd_restore
from ibdx.deps import complete_filename
Expand All @@ -14,6 +15,11 @@
cli.command('restore')(ibd_restore)


@cli.command()
def version():
print(f'ibdx {__version__}')


@cli.command()
def ls(zipfile_name: str = typer.Argument('', autocompletion=complete_filename)):
try:
Expand Down
1 change: 1 addition & 0 deletions ibdx/ibd_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def ibd_backup(
datadir: str = typer.Option(''),
) -> None:
db = MysqlConn(dbname, host, port, user, password)
tables_pattern = tables_pattern.replace('%', '*')

if not datadir:
res = db.query("show variables like 'datadir';").fetchone()
Expand Down
9 changes: 7 additions & 2 deletions ibdx/ibd_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ def ibd_restore(
datadir: str = typer.Option(''),
) -> None:
db = MysqlConn(dbname, host, port, user, password)
tables_pattern = tables_pattern.replace('%', '*')
fin_fpath = Path(fin_path)

if not zipfile.is_zipfile(fin_path):
if not fin_fpath.exists():
logger.error('--file does not exist')
return
elif not zipfile.is_zipfile(fin_fpath):
logger.error('--file is not a valid archive file')
return

Expand All @@ -37,7 +42,7 @@ def ibd_restore(
db_path = Path(datadir) / dbname
assert db_path.is_dir()

with zipfile.ZipFile(fin_path, 'r', zipfile.ZIP_DEFLATED) as zip_file:
with zipfile.ZipFile(fin_fpath, 'r', zipfile.ZIP_DEFLATED) as zip_file:
target_ibd_files = fnmatch.filter(
zip_file.namelist(),
f'{tables_pattern}.ibd',
Expand Down

0 comments on commit fe0d790

Please sign in to comment.