semvec/pypi-packages huggingface dataset:
vps-backup-utils 0.0.3
Backup Utilities for Linux VPS with MySQL and other data
License: MIT
Requires Python: >=3.7,<4.0
Keywords: backup,vps

# vps_backup_utils

<!-- [![Tests Status](https://github.com/python-poetry/poetry/workflows/Tests/badge.svg?branch=master&event=push)](https://github.com/python-poetry/poetry/actions?query=workflow%3ATests+branch%3Amaster+event%3Apush) -->
![Python 3](https://img.shields.io/badge/Python-3-blue.svg)
[![PyPI](https://img.shields.io/pypi/v/vps_backup_utils?label=PyPI)](https://pypi.org/project/vps_backup_utils/)
[![downloads](https://img.shields.io/pypi/dm/vps_backup_utils)](https://pypistats.org/packages/vps_backup_utils)

Backup Utilities for Linux VPS with MySQL and other data. 

With this package, you can write Python scripts to call cli tools. (need to install cli tools in advance)

## Supported cli

* [x] `mysqldump`
* [ ] `pg_dump`
* [x] `tar`
* [x] `gzip`
* [x] `rsync` (to remote servers)

## Usage

1. Run `pip install vps_backup_utils` on your VPS
2. Write a Python script like the below one, and save on your VPS
3. Add this script to your VPS's crontab

```python
#!/usr/bin/env python

from vps_backup_utils import VPSBackupUtils

backuper = VPSBackupUtils('~/backup')
backuper.remove_old_backups(30)
backuper.mysqldump_backup(
    backup_prefix='project1',
    host='127.0.0.1',
    port='3306',
    user='root',
    password='password',
    databases=None,
    gzipped=True
)
backuper.tar_backup(
    backup_prefix='project1',
    src_folder='/path/to/project1/data'
)
backuper.mysqldump_backup(
    backup_prefix='another_project',
    host='127.0.0.1',
    port='3307',
    user='root',
    password='password',
    databases=None,
    gzipped=True
)
backuper.rsync_backups_to_remote(
    host='another.server',
    user='user',
    remote_backup_path='~/server1-backup',
    port='22222',
    delete_mode=True
)
```

## develop

### install dependencies

```
pip3 install poetry
poetry install
```

### test on host machine

Write your codes to `main.py`, and just run.

```
python3 main.py
```

### run unit tests on host machine (not recommended)

```
poetry run pytest
```

### run unit tests on docker (recommended)

```
docker-compose up -d mysql postgresql
docker-compose up pytest --build
```

### build & publish

```
poetry update && poetry build && poetry publish
```
random-readline 0.1.0
Randomized fast readline for large text files.
License: MIT

# random-readline

Randomized fast readline for large text files.

## Install

```sh
pip install random_readline
```

## Usage

```python
from random_readline import readline

# lines are shuffled by default.
n_lines, read = readline("text.txt")

for line in read():
    print(line)
```

### Sequencial read

```python
from random_readline import readline

# lines are not shuffled as it is.
n_lines, read = readline("text.txt", shuffle=False)

for line in read():
    print(line)
```

### Gzipped file

```python
import gzip
from random_readline import readline

n_lines, read = readline("text.txt.gz", opener=gzip.open)

for line in read():
    print(line)
```

### Control the frequency of seeking

Since random seeking can be very slow with gzipped files, the readline function has an option `chunk_size` to control the frequency of seeking.

This value is set to `1` by default, which means that a seeking is performed every single line to read the entire file completely at random.

Increasing the value of `chunk_size` will reduce the frequency with which seekings are performed, thus improving performance in exchange for randomness.

```python
import gzip
from random_readline import readline

# lines will be randomized by every 100 lines
n_lines, read = readline("text.txt.gz", opener=gzip.open, chunk_size=100)

for line in read():
    print(line)
```