Created
January 18, 2022 05:07
-
-
Save iandark/19e83ea2e854cd81dcf5a909db1283ec to your computer and use it in GitHub Desktop.
Backup redis into rdb file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| ## | |
| # Path for the original RDB file | |
| ## | |
| rdbPath=/var/lib/redis | |
| rdbFile=dump.rdb | |
| ## | |
| # Path for the backup | |
| ## | |
| backupPath=$HOME/Downloads | |
| backupFile=dump.rdb | |
| rdbFilepath="$rdbPath/$rdbFile" | |
| backupFilepath="$backupPath/$backupFile" | |
| redis-cli save | |
| if test -f "$rdbPath/$rdbFile"; then | |
| # Stop Redis for backup | |
| sudo systemctl stop redis.service | |
| # Backup the original redis file | |
| echo "Making backup from $rdbFilepath -> $backupFilepath" | |
| cp -R $rdbFilepath $backupFilepath || { | |
| echo "Failed to copy file $rdbFilepath -> $rdbBackupFilepath" | |
| exit 1 | |
| } | |
| # Start Redis after completion | |
| sudo systemctl start redis.service | |
| echo "Success! backed-up at $backupFilepath" | |
| else | |
| echo "There's something wrong, maybe you don´t have a dump rdb file." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment