Beispiel #1
0
        private static bool ExecBackup()
        {
            using (var webClient = new GearHostWebClient())
            {
                webClient.Headers.Add("Authorization", string.Format("bearer {0}", apiKey));
                DatabasesDTO dto = null;
                try
                {
                    var databasesJson = webClient.DownloadString("https://api.gearhost.com/v1/databases");
                    dto = new JavaScriptSerializer().Deserialize <DatabasesDTO>(databasesJson);
                }
                catch (Exception)
                {
                    Console.WriteLine("Error downloading API data. Check your API key");
                    return(false);
                }

                var database = dto.databases.FirstOrDefault(d => string.Compare(d.name, dbName, StringComparison.OrdinalIgnoreCase) == 0);
                if (database == null)
                {
                    Console.WriteLine("Database not found. Check your database name.");
                    return(false);
                }
                Console.WriteLine("Database found. Executing backup...");
                string localFileName = dbName + "_" + DateTime.Now.ToUnixTimestamp() + ".zip";
                string localPath     = Path.Combine(downloadsPath, localFileName);

                webClient.DownloadFile(string.Format("https://api.gearhost.com/v1/databases/{0}/backup", database.id), localPath);
            }

            return(true);
        }
Beispiel #2
0
        private static bool ExecBackup()
        {
            using (var webClient = new GearHostWebClient())
            {
                webClient.Headers.Add("Authorization", string.Format("bearer {0}", apiKey));
                DatabasesDTO dto = null;
                try
                {
                    var databasesJson = webClient.DownloadString("https://api.gearhost.com/v1/databases");
                    dto = new JavaScriptSerializer().Deserialize<DatabasesDTO>(databasesJson);
                }
                catch (Exception)
                {
                    Console.WriteLine("Error downloading API data. Check your API key");
                    return false;
                }

                var database = dto.databases.FirstOrDefault(d => string.Compare(d.name, dbName, StringComparison.OrdinalIgnoreCase) == 0);
                if (database == null)
                {
                    Console.WriteLine("Database not found. Check your database name.");
                    return false;
                }
                Console.WriteLine("Database found. Executing backup...");
                string localFileName = dbName + "_" + DateTime.Now.ToUnixTimestamp() + ".zip";
                string localPath = Path.Combine(downloadsPath, localFileName);

                webClient.DownloadFile(string.Format("https://api.gearhost.com/v1/databases/{0}/backup", database.id), localPath);
            }

            return true;
        }