root拥有的文件的file_get_contents [英] file_get_contents for file owned by root

查看:90
本文介绍了root拥有的文件的file_get_contents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的MariaDB服务器设置远程备份(在64位Ubuntu 12.04上运行).

I am in the process of setting up a remote backup for my MariaDB server (running on 64 bit Ubuntu 12.04).

此过程的第一步很容易-我正在使用

The first step in this process was easy - I am using automysqlbackup as explained here. The next step is mostly pretty easy - I am uploading the latest backup in the folder /var/lib/automysqlbackup/daily/dbname to a remote backup service (EVBackup in the present case) via SFTP. The only issue I have run into is this

由automysqlbackup在该文件夹中创建的文件的名称格式为 dbname_2014-04-25_06h47m.Friday.sql.gz ,并由root拥有.建立最新备份文件的名称不是问题.但是,一旦获得它,我将无法使用file_get_contents,因为它是 root 用户所有,并且其权限设置为600.也许有一种运行shell脚本的方法,该脚本可以将我的内容?关于shell脚本,我是一个新手.对于那些能够提出一种从PHP获取备份数据的方法的人,我深感荣幸.

The files created in that folder by automysqlbackup bear names in the format dbname_2014-04-25_06h47m.Friday.sql.gz and are owned by root. Establishing the name of the latest backup file is not an issue. However, once I have got it I am unable to use file_get_contents since it is owned by the root user and has its permissions set to 600. Perhaps there is a way to run a shell script that fetches me those contents? I am a novice when it comes to shell scripts. I'd be much obliged to anyone who might be able to suggest a way to get at the backup data from PHP.

推荐答案

为了使任何人遇到该线程,我在下面创建的功能齐全的脚本下方给出了此内容.假定您已按照

For the benefit of anyone running into this thread I give below the fully functional script I created. It assumes that you have created and shared your public ssh_key with the remote server (EVBackup in my case) as described here.

就我而言,我不得不处理另外一个复杂的问题-我正在设置我的第一台服务器,但还要另外几台.它们的域名格式为svN.example.com,其中N为1、2、3等.

In my case I had to deal with one additional complication - I am in the process of setting up the first of my servers but will have several others. Their domain names bear the form svN.example.com where N is 1, 2, 3 etc.

在我的EVBackup帐户上,我创建了带有相同名称的文件夹,分别为sv1,sv2等.我想创建一个可以从我的任何服务器上安全运行的脚本.这是带有一些注释的脚本

On my EVBackup account I have created folders bearing the same names, sv1, sv2 etc. I wanted to create a script that would safely run from any of my servers. Here is that script with some comments

#! /bin/bash
# Backup to EVBackup Server

local="/var/lib/automysqlbackup/daily/dbname"
#replace dbname as appropriate

svr="$(uname -n)"
remote="$(svr/.example.com/)"
#strip out the .example.com bit to get the destination folder on the remote server
remote+="/"

evb="user@user.evbackup.com:"
#user will have to be replaced with your username
evb+=$remote

cmd='rsync -avz -e "ssh -i /backup/ssh_key" '
#your ssh key location may well be different

cmd+=$local
cmd+=$evb
#at this point cmd will be something like
#rsync -avz -e "ssh -i /backup/ssh_key" /home bob@bob.evbackup.com:home-data

eval $cmd

这篇关于root拥有的文件的file_get_contents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆