Skip to content

Instantly share code, notes, and snippets.

@iandark
Created January 18, 2022 05:07
Show Gist options
  • Select an option

  • Save iandark/19e83ea2e854cd81dcf5a909db1283ec to your computer and use it in GitHub Desktop.

Select an option

Save iandark/19e83ea2e854cd81dcf5a909db1283ec to your computer and use it in GitHub Desktop.
Backup redis into rdb file
#!/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