Redis can't write logs or backup but I need to backup whats currently in memory - permissions

Someone before me setup a redis instance (version 2.6).
But for some reason, whoever set this, had
Placed the config file etc like this /etc/redis.conf
The dir config has ./ set, like this dir ./
The instance is being run as non-root.
Like this:
$ ps aux | grep "redis"`
user /home/user/redis-stable/src/redis-server /etc/redis.conf
Logging is going to /dev/null, because daemonize yes && logfile stdout
So it is unable to create backups in /etc/ because it doesn't have permissions (I'm guessing), and I can't even see what is going on because the logs are going to /dev/null.
I want to make a backup so I can turn redis off to fix all these things, without losing any data. Any ideas?
I've tried:
touch /etc/dump.rdb
chown user:users /etc/dump.rdb
But it is still not able to write. I'm guessing it might have a temp file it tries to write to before it moves it to /etc/dump.rdb
After looking at Redis source code, it does seem like there is a temp file: https://github.com/antirez/redis/blob/04542cff92147b9b686a2071c4c53574771f4f88/src/rdb.c#L986
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
Also tried
redis 127.0.0.1:6379> config set logfile /home/user/redis.log
(error) ERR Unsupported CONFIG parameter: logfile

Run:
config get dir
and you would see the directory where redis is saving rdb.
Run:
config set dir /home/user/
to change the rdb dump directory to /home/user.
then run:
redis-cli -p <port> bgsave
This would initiate a rdb dump.
Hope this helps.

Related

Redis don't start

I have redis server 3.0.6 and ubuntu 16.04.
my config file
tcp-keepalive 60
#bind 127.0.0.1
requirepass qwerty
maxmemory-policy noeviction
appendonly yes
appendfilename redis-test.aof
and redis server don't run
Can't open the append-only file: Read-only file system
The error message is pretty clear: The file system on which redis-test.aof resides is mounted as read-only. The whole purpose of this file is to write changes to disk. So the disk must be writable.
Check if you used the ro option while mounting the drive. Run
$ mount
to list all the mountpoints. Check the one on which you want your aof file to reside.
To remount the disk as read-write, use the following command:
$ sudo mount -o remount,rw /partition/identifier /mount/point
If that doesn't help, see the system logs if there are any file system errors. To correct these, you will need to run fsck.

Where is the data directory in Redis?

After writing some data to a redis server, I could read the data from a client.
However, how can I find the data directory on the file system?
Quickest method: use redis-cli.
redis-cli config get dir
If you have authentication configured, you will need to pass that in using -a password Replacing "password" with your password.
Find your Redis configuration directory, probably /etc/redis. Then look in the config file called redis.conf and find the line that starts dir.
It will look similar to this:
dir /etc/redis/database
This will do the job slowly but surely if you can't be bothered to look :-)
sudo find / -name "redis.conf" -exec grep "^dir" {} \; 2> /dev/null
dir /etc/redis
or if you want the config filename as well:
sudo find / -name "redis.conf" -exec grep -H "^dir" {} \; 2> /dev/null
/private/etc/redis/redis.conf:dir /etc/redis
Other possibilities you can check are whether Redis was started with a custom config file as its first parameter like this:
redis-server /path/to.custom/config-file
or with the dir option set on the commandline like this:
redis-server dir /path/to/data
Use
ps -aef | grep redis
to look for these options.
Because Redis config file can be located in several possible places (depending on the system or container, such as /opt/redis/ in my case), a general solution to find the currently configured location of the RDB file (as set using dir in redis.conf - if config file is used at all*) is:
$ cat $(cd / && find | grep redis.conf) | grep dir
*Note that true to its simplicity Redis by default ships without any config files (using built-in configuration which depends on the version, see docs), and this is indeed the case for the official redis:latest container.

/var/run/redis/redis.pid exists, process is already running or crashed

Redis went quite on me.
user#mycomputer:~$ redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
I try to restart the service by doing this
sudo /etc/init.d/redis_6379 stop
/var/run/redis/redis.pid exists, process is already running or crashed
But no luck. Logs didn't show an error as well.
Got it fixed by backing up the redis.rdp file mine is located at
/var/lib/redis
check your config file "/etc/redis/redis.conf" for the rdp file's location and do this
sudo mv /var/lib/redis/redis.rdp /var/lib/redis/redis_backup.rdp
Then recreate the the redis.rdp file
sudo touch redis.rdp
Run the redis-server with the conf and it should work
sudo redis-server /etc/redis/redis.conf
Get it fixed in a tidy way: Recreate the the redis.rdp file as suggested here in one of answer, will purge all the cache recorded so far and redis will start up fresh with no cache data.
This is a warning message to notify system crash / improper shutdown: "/var/run/redis/redis.pid exists, process is already running or crashed"
Just delete /var/run/redis/redis.pid file and restart the server again.
Note: You might have lost latest cache changes due to untidy shutdown, which weren't flushed into the disk. This data loss can be minimized using frequent disk flush configuration in redis conf file(in my case it is #/etc/redis/6379.conf)
save 900 1
save 300 10
save 60 10000
Or try AOF persistence, more details [here][1]
Depends on how you installed redis, the pid can be found on /var/run/redis_6379.pid.
What happened is that redis crashed, but the pid is still there. So you just have to delete it.
sudo rm -f /var/run/redis_6379.pid
Then start redis again:
sudo /etc/init.d/redis_6379 start
If you can't find it, I suggest installing redis "more properly". Follow redis quickstart guide in the Installing Redis more properly section.
You can find it here:
https://redis.io/topics/quickstart
Run the redis-server with config.
sudo redis-server redis.conf

Dotcloud: how to load a redis backup file on startup

I can't find a way to have redis load my own dump.rdb backup file on startup, on dotcloud. I can see in the server logs that redis is loading a file, but I don't know where it is (and I can't find it)
[144] 03 Jul 21:01:18 * DB loaded from disk: 0 seconds
I've tried to put the dump.rdb file in /var/lib/redis directory but it doesn't help
Thanks for any help
I've found what I made wrong: upon restart, redis makes a dump, and was overwriting my dump file with an empty dump and reloading the empty dump on startup. Correct process is:
~$ dotcloud ssh [your service]
~$ sudo /etc/init.d/redis stop
~$ cp [your dump] /var/lib/redis/dump.rdb
~$ sudo /etc/init.d/redis start

redis dump.rdb / saving small files

Context
I'm using redis. The database is < 100 MB.
However, I want to make daily backups.
I'm also running on Ubuntu Server 12.04
When type in:
redis-cli save
I don't know where dump.rdb is saved to (since redis is started as a service and not in my local directory).
Questions:
How do I find where redis is saving my dump.rdb to?
Is there someway that I can specify a filename to 'save', so I type in something like:
redis-cli save ~/db-2012-06-24.rdb
Thanks
To be a little more helpfull... How to find or set where redis is saving the dump.rdb file (ubuntu server):
First find you redis.conf file: In your terminal run:
ps -e aux | grep redis
I found my redis.conf file in:
var/etc/redis/
If yours is the same place then open the file with:
pico var/etc/redis/redis.conf
Look for:
# The filename where to dump the DB
dbfilename dump.rdb
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis
Depending on your setting for "dbfilename" and "dir" then that is where you find your redis dump.rdb file.
Update:
To see your redis configurations just run:
redis-cli CONFIG GET *
You can set the file location on the redis.conf file (which you start the server with)
look at the server configuration for that:
# The filename where to dump the DB
dbfilename dump.rdb
finding the location of the currently saved file, it depends on how you start the server - where you have the redis-server file - i think you can find it with ps -e aux | grep redis or ps -e | grep redis
On my (default, Ubuntu) setup the db file is in
/var/lib/redis/redis.rdb
As Christoffer points out, you can see all the settings from the command-line client with
CONFIG GET *
One liner to get both directory and dump file name
echo "CONFIG GET *" | redis-cli | grep -e "dir" -e "dbfilename" -A1
In mac,
the location of dump.rdb is at /usr/local/etc/dump.rdb.
the location of redis.conf is at /usr/local/etc/redis.conf.
In order to find the location use the command find - sudo find / -name "redis.conf"