Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public static bool AppInit()
        {
            CurrentConfig = new SqlBackUpperLibConfig(ASSEMBLY_NAME, SQLBACKUPPER_CONFIG_FILE_NAME);
            if (CurrentConfig.IsSetConfig)
            {
                Connection.AttachServerTypeObjects(CurrentConfig.Connections, CurrentConfig.ServerTypes);
            }
            else
            {
                return(MessageBoxes.CreateConfigFile() && CurrentConfig.WriteConfig());

                //if (MessageBoxes.CreateConfigFile())
                //{
                //    if (!CurrentConfig.WriteConfig())
                //        return false;
                //}
                //else
                //    //Log.Add("Config file is not set. Exit..");
                //    return false;
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        void Apply()
        {
            if (this.connections.Any() && !this.serverTypes.Any())
            {
                MessageBoxes.Warning(this, "Необходимо добавить хотя бы один тип сервера");
                return;
            }

            if (!this.connections.ToList().All(x => x.ServerType != null))
            {
                MessageBoxes.Warning(this, "У некоторых соединений не установлен тип сервера");
                return;
            }

            SqlBackUpperLibConfig config = App.CurrentConfig;

            config.Connections = this.connections.ToList();
            config.ServerTypes = this.serverTypes.ToList();

            //
            config.WriteConfig();

            Close();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Display.SetWindowStyle(ProcessWindowStyle.Hidden);

            // init config file (and current log file)
            //SqlBackUpperConfig config = new SqlBackUpperConfig(args);
            SqlBackUpperLibConfig config = new SqlBackUpperLibConfig(ASSEMBLY_NAME, args);

            if (!config.IsSetConfig)
            {
                OnFinish(config);
                //Log.Add("Config file is not set. Exit..");
                return;
            }

            //ProcessWindowStyle windowStyle = config.WindowStyle;
            Display.SetWindowStyle(config.WindowStyle);

            // connecting to the server & execute sql query
            List <Connection> connections = config.Connections;

            if (connections != null)
            {
                if (config.UniteSameInst)
                {
                    // use grouping by server
                    List <ConnectionGroup> groups = ConnectionGroup.SpritToGroups(connections);
                    foreach (ConnectionGroup group in groups)
                    {
                        Log.AddLine();
                        SqlQuery.ExecuteGroup(group, config.ConnectionGroupMask, config.Timeout, config.SqlQueryMask, config.BackupNameMask);
                        foreach (Connection conn in group.Connections)
                        {
                            FileSystem.DeleteOldFiles(conn.BackupPath, conn.MaxBackups, conn.Database + "*");
                        }
                    }
                }
                else
                {
                    // execute all queries successively
                    foreach (Connection conn in connections)
                    {
                        Log.AddLine();
                        string backupName = conn.Database + String.Format(config.BackupNameMask, DateTime.Now);
                        SqlQuery.Execute(conn, config.ConnectionMask, config.Timeout, config.SqlQueryMask, backupName);
                        FileSystem.DeleteOldFiles(conn.BackupPath, conn.MaxBackups, conn.Database + "*");
                    }
                }
            }
            else
            {
                Log.Add("Error in config ([Connections] == null)");
            }

            // delete extra log files
            OnFinish(config);
            //FileSystem.DeleteOldFiles(config.LogPath, config.MaxLogs, "*.log");

            //Log.Add("Finish");
            ////
            //if ((windowStyle == ProcessWindowStyle.Normal || windowStyle == ProcessWindowStyle.Maximized) && config.ReadKeyInFinish)
            //{
            //    Console.WriteLine("Press any key to exit..");
            //    Console.ReadKey();
            //}
        }