// *************************************************************************************************************************
        // 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)
        {
            string connectionStringWithKey = "";
            string connectionString;

            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);
            }

            // Use ConnectionString if set, if not prompt for SAS token
            if (connectionStringWithKey == "")
            {
                Console.WriteLine("Please enter your account name and then hit enter.");
                string accountName = Console.ReadLine();
                Console.WriteLine("Please enter an account level SAS key generated by your Azure Administrator.");
                Console.WriteLine("e.g. ?sv=2016-05-31&ss=bfqt&srt=sco&sp=rwdl&st=2017-04-24T17%3A13%3A00Z&se=2017-04-25T17%3A13%3A00Z&sig=usADJWPXWVct%2Fxxw8GTSOVv2t7eC7TtnxKeINvu72YM%3D");
                string sasKey = Console.ReadLine();

                connectionString = "BlobEndpoint=https://" + accountName + ".blob.core.windows.net;SharedAccessSignature=" + sasKey;
            }
            else
            {
                connectionString = connectionStringWithKey;
            }

            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);
        }
Пример #2
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);
        }