Пример #1
0
        // *************************************************************************************************************************
        // Instructions: This sample can only be run using an Azure Storage Account. When the sample is run, the user will be
        // prompted to enter an Azure Storage account name and a blob service or an account SAS key that has read/write access to
        // the blob service.
        //
        // To run the sample you need to supplement two arguments in the Linux commandline
        //      1. First argument is the option to backup or restore data. Simply provide 'backup' or 'restore' keyword
        //      2. Local directory to be backed up or restored to. Full path is needed
        //
        // Sample usage:
        //              dotnet run  <first argument: backup/restore> <second argument: /home/sampledirectory>
        //              dotnet run backup /home/sampledirectory
        //              dotnet run restore /home/sampledirectory
        //
        // *************************************************************************************************************************

        public static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                System.Console.WriteLine("Please enter the following parameters.");
                System.Console.WriteLine("Usage: <appname> <backup/restore> <local directory path>");
                System.Console.WriteLine("e.g.: Backup2Azure.exe backup /home/");

                return(1);
            }

            Console.WriteLine("Please enter your account name and then hit enter.");
            string accountName = Console.ReadLine();

            Console.WriteLine("Please enter a SAS key generated by your Azure Administrator.");
            string sasKey = Console.ReadLine();

            string connectionString = "BlobEndpoint=https://" + accountName + ".blob.core.windows.net;SharedAccessSignature=" + sasKey;

            DirectoryInfo localDir = new DirectoryInfo(args[1]);

            if (args[0] == "restore")
            {
                Console.WriteLine("Please type the containername you want to restore from:");

                Storage connect = new Storage();
                var     task    = connect.ListContainers(connectionString);
                task.Wait();

                string containername = Console.ReadLine();

                Download downloadFromAzure = new Download();
                var      downloadtask      = downloadFromAzure.doDownload(containername, localDir, connectionString);
                downloadtask.Wait();
            }
            else if (args[0] == "backup")
            {
                Upload upload2Azure = new Upload();
                var    copytask     = upload2Azure.doCopy(localDir, connectionString);
                copytask.Wait();
            }

            Console.ReadLine();
            return(0);
        }