- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 GoDaddy 上有一个服务器和一个域名.
我想为要上传到 Google Drive 的文件创建备份
这样我所有的文件和数据库都在 Google Drive 上有它们的数据.
我的数据库使用 PHP
和 MySQL
经过一些研究,我找到了“Automatically backing up your web server files to GoogleDrive with PHP”并按照他说的做了。
我已经从 backuptogoogledrive repository 下载文件 google-api-php-client
.
我有一个客户端 ID、客户端密码 和一个authCode
我编辑了 setting.inc 并放入了我自己的客户端 ID、客户端密码 和 授权码。我还输入了我的 MySQL
用户名、密码和主机名。
在此页面 backuptogoogledrive
中,它应该创建一个 .tar.gz
文件夹,并且此文件夹应该 包含我的网站文件。然后,这个文件夹应该上传到我的Google Drive对我的数据库做同样的事情。
<?php
set_time_limit(0);
ini_set('memory_limit', '1024M');
require_once("google-api-php-client/src/Google_Client.php");
require_once("google-api-php-client/src/contrib/Google_DriveService.php");
include("settings.inc.php");
if($authCode == "") die("You need to run getauthcode.php first!\n\n");
/* PREPARE FILES FOR UPLOAD */
// Use the current date/time as unique identifier
$uid = date("YmdHis");
// Create tar.gz file
shell_exec("cd ".$homedir." && tar cf - ".$sitedir." -C ".$homedir." | gzip -9 > ".$homedir.$fprefix.$uid.".tar.gz");
// Dump datamabase
shell_exec("mysqldump -u".$dbuser." -p".$dbpass." ".$dbname." > ".$homedir.$dprefix.$uid.".sql");
shell_exec("gzip ".$homedir.$dprefix.$uid.".sql");
/* SEND FILES TO GOOGLEDRIVE */
$client = new Google_Client();
// Get your credentials from the APIs Console
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($requestURI);
$client->setScopes(array("https://www.googleapis.com/auth/drive"));
$service = new Google_DriveService($client);
// Exchange authorisation code for access token
if(!file_exists("token.json")) {
// Save token for future use
$accessToken = $client->authenticate($authCode);
file_put_contents("token.json",$accessToken);
}
else $accessToken = file_get_contents("token.json");
$client->setAccessToken($accessToken);
// Upload file to Google Drive
$file = new Google_DriveFile();
$file->setTitle($fprefix.$uid.".tar.gz");
$file->setDescription("Server backup file");
$file->setMimeType("application/gzip");
$data = file_get_contents($homedir.$fprefix.$uid.".tar.gz");
$createdFile = $service->files->insert($file, array('data' => $data, 'mimeType' => "application/gzip",));
// Process response here....
print_r($createdFile);
// Upload database to Google Drive
$file = new Google_DriveFile();
$file->setTitle($dprefix.$uid.".sql.gz");
$file->setDescription("Database backup file");
$file->setMimeType("application/gzip");
$data = file_get_contents($homedir.$dprefix.$uid.".sql.gz");
$createdFile = $service->files->insert($file, array('data' => $data, 'mimeType' => "application/gzip",));
// Process response here....
print_r($createdFile);
/* CLEANUP */
// Delete created files
unlink($homedir.$fprefix.$uid.".tar.gz");
unlink($homedir.$dprefix.$uid.".sql.gz");
?>
现在的问题是我有两个数据库文件夹并且没有问题,还有第二个文件夹用于文件。但是这个文件夹里面没有任何文件。
我该如何解决这个问题?
// User home directory (absolute)
$homedir = "/home/mhmd2991/public_html/"; // If this doesn't work, you can provide the full path yourself
// Site directory (relative)
$sitedir = "public_html/";
最佳答案
似乎备份脚本无法找到存储站点文件的目录。
引用您进行备份所遵循的教程:
// User home directory (absolute)
$homedir = trim(shell_exec("cd ~ && pwd"))."/"; // If this doesn't work, you can provide the full path yourself
// Site directory (relative)
$sitedir = "www/";
首先确保 $sitedir
已正确设置站点文件目录的相对路径(从主目录)。
它可能与 www/
不同,例如 public_html/
表示托管在 GoDaddy 上的网站。
如果上述正确,请尝试使用主目录的绝对路径手动设置 $home
变量。
更新
$homedir
是主目录,$sitedir
是相对于 $homedir
因此查看您发布的代码很可能存在错误,两个变量应该是:
// User home directory (absolute)
$homedir = "/home/mhmd2991/"; // <-- FIXED HERE
// Site directory (relative)
$sitedir = "public_html/";
这假设您的网站根目录是 public_html
并且位于您的主目录 mhmd2991
再次确保您的网站根目录实际上是 public_html
而不是 www
或 html
或其他任何内容。使用终端检查。
关于php - 使用 PHP 将文件备份到谷歌驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46828881/
这两个包看起来非常相似: http://www.passportjs.org/packages/passport-google-oauth2/ http://www.passportjs.org/pa
我想在我的网站上添加通过 Google 和 Twitter 登录的按钮。我需要只使用应用程序的客户端而不是服务器端来完成此操作。但我没有找到任何 API。对于我发现的所有内容,我需要使用带有 key
我使用此链接通过 google plus 共享我的页面。 https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fcompany%2
我正在尝试学习 google API,并且我的经验是使用 Python,因此我尝试使用 google api python 客户端来访问一些 google 服务,但在构建服务对象时遇到错误。 从 ap
在其实际的实时托管平台上构建实时站点的努力中,有没有办法告诉谷歌不要索引该网站?我发现了以下内容: http://support.google.com/webmasters/bin/answer.py
我正在开发一个 iOS 应用程序。当我运行用于 google+ 登录的程序时,在我点击允许访问按钮后,会显示此消息。 You've reached this page because we have
我有一个非常复杂的网站,每个页面包含 11 个 js 文件。 我最近添加了 google +1 按钮,代码如下: 这会正确显示 +1 按钮,直到我单击它。当我单击它时,出现此错误:https://
我正在尝试使用 google API 创建一个 html 文件,以便在 google MAPS 上显示 KML 文件。 这是 HTML 代码: function initMap() {
我是使用 Google Benchmark 的新手,在本地运行代码与在 Quick-Bench.com 上运行代码时,我收到了运行相同基准测试(下方)的不同结果,该基准测试使用 C++ 检索本地时间.
我已按照 Google 网站上的说明通过添加以下元标记在我的 AngularJS 网站上启用 Ajax 抓取: 呈现的内容有一些链接,如: User 1 User 2 User 3 还有一些呈现动态
通过 Google 手册实现 Google AppInvite - link . 启动 Invite Activity 并在 LogCat 中获取下一步: E/AppInviteAgent: Get
那么有人用过 Google 的 Go 吗?我想知道数学性能(例如触发器)与其他具有垃圾收集器的语言(如 Java 或 .NET)相比如何? 有人调查过吗? 最佳答案 理论性能:纯 Go 程序的理论性能
Stackdriver 测试我的网站启动速度慢 我们使用 cloudflare 作为我们的站点 CDN 提供商。我们使用 stackdriver 从外部测试站点可用性,我们将时间检查间隔设置为 1 分
我正在尝试使用 stax.GeneralConv() ( https://jax.readthedocs.io/en/latest/_modules/jax/experimental/stax.htm
我有一个从谷歌金融中提取日内数据的软件。但是,由于昨天 Google 更新了 API,所以软件报错了 Conversion from string HTML HEAD meta http-equiv=
我们在尝试从 Google 获取 oAuth token 时遇到“redirect_uri_mismatch”错误: [client 127.0.0.1:49892] {\n "error" : "
我的网站正在使用 Google reCAPTCHA 控件,但我听说它被阻止了 中国,反正我看到有人报告说将 API 更改为 https://www.recaptcha.net在中国工作? Anyone
背景 WordPress Google Adsense 谷歌自动插入 anchor 定广告 https://pptmon.com 问题 如下图所示,主播广告的容器高度太大了! 如何调整高度? 这是谷歌
我在使用 Google Colab 时遇到问题。当我想制作一个新的 Python3 Notebook 时,由于我登录了我的 Google 帐户,因此无法加载刚刚打开的新页面。 我该怎么办? 感谢您的帮
我正在使用 facebook和 google oauth2使用 passport js 登录, 有了这个流 用户点击登录按钮 重定向到 facebook/google auth 页面(取决于用户选择的
我是一名优秀的程序员,十分优秀!