Skip to content

Commit 490631b

Browse files
committed
Add support for Redis backups
1 parent e49c6b6 commit 490631b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A script to automatically back up all databases running under docker on a host
99
- MariaDB
1010
- MySQL
1111
- PostgreSQL
12+
- Redis
1213

1314
## Installation
1415

db-auto-backup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def backup_mysql(container: Container) -> str:
5151
return f"bash -c 'mysqldump {auth} --all-databases'"
5252

5353

54+
def backup_redis(container: Container) -> str:
55+
"""
56+
Note: `SAVE` command locks the database, which isn't ideal.
57+
Hopefully the commit is fast enough!
58+
"""
59+
return "sh -c 'redis-cli SAVE > /dev/null && cat /data/dump.rdb'"
60+
61+
5462
BACKUP_PROVIDERS: list[BackupProvider] = [
5563
BackupProvider(
5664
patterns=["postgres"], backup_method=backup_psql, file_extension="sql"
@@ -60,6 +68,9 @@ def backup_mysql(container: Container) -> str:
6068
backup_method=backup_mysql,
6169
file_extension="sql",
6270
),
71+
BackupProvider(
72+
patterns=["redis"], backup_method=backup_redis, file_extension="rdb"
73+
),
6374
]
6475

6576

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ services:
2929
restart: unless-stopped
3030
environment:
3131
- MYSQL_ROOT_PASSWORD=password
32+
33+
redis:
34+
image: redis:alpine
35+
restart: unless-stopped

0 commit comments

Comments
 (0)