本文介绍了更改 redis 转储的默认文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 cron 作业,它在一个名为deployer"的用户下运行,访问权限有限.cron 作业正在执行我的 redis 数据库的备份,结果是/var/lib/redis/dump.rdb.

I have a cron job, which is running under a user called 'deployer' with limited access. The cron job is performing a backup of my redis database resulting in a dum /var/lib/redis/dump.rdb.

现在 cron 作业现在尝试执行 /bin/gzip -c/var/lib/redis/dump.rdb >/home/deployer/Backup/.tmp/redis_backup/databases/Redis/dump.rdb.gz 在将其发送到 S3 之前.问题是,/var/lib/redis/dump.rdb 的权限是-rw-rw----,所以我收到以下错误:

Now the cron job now tries to perform a /bin/gzip -c /var/lib/redis/dump.rdb > /home/deployer/Backup/.tmp/redis_backup/databases/Redis/dump.rdb.gz before shipping it off to S3. The problem is, that the permissions on /var/lib/redis/dump.rdb is -rw-rw----, so I get the following error:

gzip: /var/lib/redis/dump.rdb: Permission denied

所以我的问题是,我对给我的部署者用户更广泛的权限不感兴趣,所以我希望每次运行 cron 作业时都会创建的转储具有其他权限.

So my question is, I'm not interested in giving my deployer user wider permissions, so I would like that dump, that is being created every time the cron job is run, to have other permissions.

我怎样才能以最简单的方式做到这一点?

How can I accomplish that the simplest way?

推荐答案

Redis 转储文件是使用标准 fopen('...',"w") 调用创建的.所以访问权限实际上是从当前的umask继承而来.

The Redis dump file is created with a standard fopen('...',"w") call. So the access rights are actually inherited from the current umask.

在启动 Redis 服务器本身之前,尝试使用 umask 命令更改用于启动 Redis 服务器的脚本或 shell 中的 umask:

Try to alter the umask in the script or the shell used to launch the Redis server, before launching the Redis server itself, by using the umask command:

$ umask 022

此命令将更改掩码,以便创建具有 644 访问权限(666 是默认访问权限)的新文件.

This command will change the mask so that new files will be created with 644 access rights (666 being the default access rights).

这篇关于更改 redis 转储的默认文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:15