Add database setup (LosaGame, LosaGame_log, LosaLogData, Backup, backup/restore) and the tested one-PC server config

This commit is contained in:
LosaDev committed 2026-11-07 20:36:19 +07:00
1 parent c198676e97
commit 17e8463b49
243 files changed
+1405092

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
-- LosaDev 2019: creates LosaGame, LosaGame_log, LosaLogData and Backup (empty). Run first.
-- Backup stays empty: procedures such as game_practice_rank_reward and game_region_backup_point create
-- their own tables in it (SELECT ... INTO [Backup].dbo.<name>), so the game login must own it.
-- sqlcmd -S <server> -E -f 65001 -v DB_COLLATE=DEFAULT -i 00_create_databases.sql
-- DB_COLLATE=DEFAULT = the instance's collation (recommended: install SQL Server with
-- Korean_Wansung_CI_AS so Korean text in varchar columns survives). Otherwise e.g. Korean_Wansung_CI_AS.
USE [master]
GO
DECLARE @c nvarchar(128) = N'$(DB_COLLATE)', @sql nvarchar(max), @db sysname
IF @c = N'DEFAULT' SET @c = N''
DECLARE d CURSOR LOCAL FAST_FORWARD FOR SELECT v FROM (VALUES (N'LosaGame'), (N'LosaGame_log'), (N'LosaLogData'), (N'Backup')) t(v)
OPEN d
FETCH NEXT FROM d INTO @db
WHILE @@FETCH_STATUS = 0
BEGIN
IF DB_ID(@db) IS NULL
BEGIN
SET @sql = N'CREATE DATABASE ' + QUOTENAME(@db) + CASE WHEN LEN(@c) > 0 THEN N' COLLATE ' + @c ELSE N'' END
EXEC (@sql)
PRINT 'created ' + @db
END
ELSE PRINT @db + ' already exists (kept)'
FETCH NEXT FROM d INTO @db
END
CLOSE d
DEALLOCATE d
GO
+14
View File
@@ -0,0 +1,14 @@
-- LosaDev 2019: SQL logins the DB agents use (ID= in each ls_dbagent.ini). The password comes from
-- the DB_PASSWORD variable (setup-db.bat asks for it); put the same value in PW= of the ls_dbagent.ini files.
USE [master]
GO
IF NOT EXISTS (SELECT 1 FROM sys.server_principals WHERE name = N'lstggame')
CREATE LOGIN [lstggame] WITH PASSWORD = N'$(DB_PASSWORD)', CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF, DEFAULT_DATABASE = [master]
ELSE
ALTER LOGIN [lstggame] WITH PASSWORD = N'$(DB_PASSWORD)'
GO
IF NOT EXISTS (SELECT 1 FROM sys.server_principals WHERE name = N'lstglog')
CREATE LOGIN [lstglog] WITH PASSWORD = N'$(DB_PASSWORD)', CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF, DEFAULT_DATABASE = [master]
ELSE
ALTER LOGIN [lstglog] WITH PASSWORD = N'$(DB_PASSWORD)'
GO
+598
View File
@@ -0,0 +1,598 @@
-- LosaDev 2019: LosaGame_Log.sql of the 2021 release (the 2019 release's own scripts lack 212 of the 401 procedures
-- the 2019 server calls; the 2021 schema matches all but a few, see 07_losadev_2019_procs.sql).
-- Unchanged except the CREATE DATABASE block. Run after 00_create_databases.sql and 01_logins.sql.
USE [master]
GO
/****** Object: Database [LosaGame_log] Script Date: 5/4/2025 8:44:49 PM ******/
-- (LosaDev) CREATE DATABASE [LosaGame_log] is done by 00_create_databases.sql
GO
ALTER DATABASE [LosaGame_log] SET COMPATIBILITY_LEVEL = 160
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [LosaGame_log].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [LosaGame_log] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [LosaGame_log] SET ANSI_NULLS OFF
GO
ALTER DATABASE [LosaGame_log] SET ANSI_PADDING OFF
GO
ALTER DATABASE [LosaGame_log] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [LosaGame_log] SET ARITHABORT OFF
GO
ALTER DATABASE [LosaGame_log] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [LosaGame_log] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [LosaGame_log] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [LosaGame_log] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [LosaGame_log] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [LosaGame_log] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [LosaGame_log] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [LosaGame_log] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [LosaGame_log] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [LosaGame_log] SET DISABLE_BROKER
GO
ALTER DATABASE [LosaGame_log] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [LosaGame_log] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [LosaGame_log] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [LosaGame_log] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [LosaGame_log] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [LosaGame_log] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [LosaGame_log] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [LosaGame_log] SET RECOVERY SIMPLE
GO
ALTER DATABASE [LosaGame_log] SET MULTI_USER
GO
ALTER DATABASE [LosaGame_log] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [LosaGame_log] SET DB_CHAINING OFF
GO
ALTER DATABASE [LosaGame_log] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [LosaGame_log] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
ALTER DATABASE [LosaGame_log] SET DELAYED_DURABILITY = DISABLED
GO
ALTER DATABASE [LosaGame_log] SET ACCELERATED_DATABASE_RECOVERY = OFF
GO
ALTER DATABASE [LosaGame_log] SET QUERY_STORE = ON
GO
ALTER DATABASE [LosaGame_log] SET QUERY_STORE (OPERATION_MODE = READ_WRITE, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 30), DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 1000, QUERY_CAPTURE_MODE = AUTO, SIZE_BASED_CLEANUP_MODE = AUTO, MAX_PLANS_PER_QUERY = 200, WAIT_STATS_CAPTURE_MODE = ON)
GO
USE [LosaGame_log]
GO
/****** Object: User [lstggame] Script Date: 5/4/2025 8:44:49 PM ******/
CREATE USER [lstggame] FOR LOGIN [lstggame] WITH DEFAULT_SCHEMA=[dbo]
GO
/****** Object: Table [dbo].[log_cash] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_cash](
[idx] [int] IDENTITY(1,1) NOT NULL,
[accountIDX] [int] NOT NULL,
[userIP] [varchar](16) NOT NULL,
[DBID] [varchar](16) NOT NULL,
[applyType] [char](2) NOT NULL,
[amount] [int] NOT NULL,
[note] [varchar](500) NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_class_buytime] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_class_buytime](
[idx] [int] IDENTITY(1,1) NOT NULL,
[classType] [int] NOT NULL,
[buyTime] [bigint] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_class_rental_history] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_class_rental_history](
[idx] [int] IDENTITY(1,1) NOT NULL,
[accountIDX] [int] NOT NULL,
[friendIDX] [int] NOT NULL,
[classType] [int] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_data_clover] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_data_clover](
[idx] [int] IDENTITY(1,1) NOT NULL,
[accountIDX] [int] NOT NULL,
[friendIDX] [int] NOT NULL,
[eventType] [smallint] NOT NULL,
[CloverCount] [int] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Index [index] Script Date: 5/4/2025 8:44:49 PM ******/
CREATE CLUSTERED INDEX [index] ON [dbo].[log_data_clover]
(
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_event_marble] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_event_marble](
[idx] [int] IDENTITY(1,1) NOT NULL,
[accountidx] [int] NOT NULL,
[userID] [varchar](20) NOT NULL,
[cpType] [int] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_event_openbeta_coin] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_event_openbeta_coin](
[idx] [int] IDENTITY(1,1) NOT NULL,
[accountIDX] [int] NOT NULL,
[coin] [int] NOT NULL,
[flag] [int] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_guild_mark] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_guild_mark](
[idx] [int] IDENTITY(1,1) NOT NULL,
[guildIDX] [int] NOT NULL,
[accountIDX] [int] NOT NULL,
[havepeso] [bigint] NOT NULL,
[markprice] [int] NOT NULL,
[nowmark] [int] NOT NULL,
[changemark] [int] NOT NULL,
[flag] [int] NOT NULL,
[userIP] [varchar](15) NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_cheer] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_cheer](
[idx] [int] IDENTITY(1,1) NOT NULL,
[cheerIDX] [int] NOT NULL,
[startDate] [int] NOT NULL,
[accountIDX] [int] NOT NULL,
[leagueIDX] [int] NOT NULL,
[teamIDX] [int] NOT NULL,
[regDate] [datetime] NOT NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_info_user] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_info_user](
[idx] [int] IDENTITY(1,1) NOT NULL,
[infoIDX] [int] NULL,
[leagueIDX] [int] NULL,
[leagueName] [nvarchar](20) NULL,
[maxRound] [smallint] NULL,
[bannerA] [int] NULL,
[bannerB] [int] NULL,
[modeType] [int] NULL,
[maxcount] [tinyint] NULL,
[autoType] [tinyint] NULL,
[announce] [nvarchar](512) NULL,
[recruitDate] [int] NULL,
[waitDate] [int] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_list] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_list](
[idx] [int] IDENTITY(1,1) NOT NULL,
[leagueIDX] [int] NULL,
[accountIDX] [int] NULL,
[startDate] [int] NULL,
[endDate] [int] NULL,
[leagueType] [tinyint] NULL,
[leagueState] [tinyint] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_list_user] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_list_user](
[idx] [int] IDENTITY(1,1) NOT NULL,
[leagueIDX] [int] NULL,
[accountIDX] [int] NULL,
[startDate] [int] NULL,
[endDate] [int] NULL,
[leagueType] [tinyint] NULL,
[leagueState] [tinyint] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_round_user] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_round_user](
[idx] [int] IDENTITY(1,1) NOT NULL,
[roundIDX] [int] NULL,
[infoIDX] [int] NULL,
[roundType1_playDate] [int] NULL,
[roundType1_presentCode1] [int] NULL,
[roundType1_presentCode2] [int] NULL,
[roundType1_presentCode3] [int] NULL,
[roundType1_presentCode4] [int] NULL,
[roundType2_playDate] [int] NULL,
[roundType2_presentCode1] [int] NULL,
[roundType2_presentCode2] [int] NULL,
[roundType2_presentCode3] [int] NULL,
[roundType2_presentCode4] [int] NULL,
[roundType3_playDate] [int] NULL,
[roundType3_presentCode1] [int] NULL,
[roundType3_presentCode2] [int] NULL,
[roundType3_presentCode3] [int] NULL,
[roundType3_presentCode4] [int] NULL,
[roundType4_playDate] [int] NULL,
[roundType4_presentCode1] [int] NULL,
[roundType4_presentCode2] [int] NULL,
[roundType4_presentCode3] [int] NULL,
[roundType4_presentCode4] [int] NULL,
[roundType5_playDate] [int] NULL,
[roundType5_presentCode1] [int] NULL,
[roundType5_presentCode2] [int] NULL,
[roundType5_presentCode3] [int] NULL,
[roundType5_presentCode4] [int] NULL,
[roundType6_playDate] [int] NULL,
[roundType6_presentCode1] [int] NULL,
[roundType6_presentCode2] [int] NULL,
[roundType6_presentCode3] [int] NULL,
[roundType6_presentCode4] [int] NULL,
[roundType7_playDate] [int] NULL,
[roundType7_presentCode1] [int] NULL,
[roundType7_presentCode2] [int] NULL,
[roundType7_presentCode3] [int] NULL,
[roundType7_presentCode4] [int] NULL,
[roundType8_playDate] [int] NULL,
[roundType8_presentCode1] [int] NULL,
[roundType8_presentCode2] [int] NULL,
[roundType8_presentCode3] [int] NULL,
[roundType8_presentCode4] [int] NULL,
[roundType9_playDate] [int] NULL,
[roundType9_presentCode1] [int] NULL,
[roundType9_presentCode2] [int] NULL,
[roundType9_presentCode3] [int] NULL,
[roundType9_presentCode4] [int] NULL,
[roundType10_playDate] [int] NULL,
[roundType10_presentCode1] [int] NULL,
[roundType10_presentCode2] [int] NULL,
[roundType10_presentCode3] [int] NULL,
[roundType10_presentCode4] [int] NULL,
[roundType11_playDate] [int] NULL,
[roundType11_presentCode1] [int] NULL,
[roundType11_presentCode2] [int] NULL,
[roundType11_presentCode3] [int] NULL,
[roundType11_presentCode4] [int] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_team] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_team](
[idx] [int] IDENTITY(1,1) NOT NULL,
[teamIDX] [int] NULL,
[leagueIDX] [int] NULL,
[startDate] [int] NULL,
[teamName] [nvarchar](20) NULL,
[leaderIDX] [int] NULL,
[leagueStartPosition] [smallint] NULL,
[leaguePosition] [smallint] NULL,
[maxcount] [tinyint] NULL,
[cheerPoint] [int] NULL,
[currentRound] [tinyint] NULL,
[factionPoint] [int] NULL,
[factionType] [tinyint] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_team_member] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_team_member](
[idx] [int] IDENTITY(1,1) NOT NULL,
[teamMemberIDX] [int] NULL,
[startDate] [int] NULL,
[accountIDX] [int] NULL,
[leagueIDX] [int] NULL,
[teamIDX] [int] NULL,
[joinType] [tinyint] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_team_member_user] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_team_member_user](
[idx] [int] IDENTITY(1,1) NOT NULL,
[teamMemberIDX] [int] NOT NULL,
[startDate] [int] NOT NULL,
[accountIDX] [int] NOT NULL,
[leagueIDX] [int] NOT NULL,
[teamIDX] [int] NOT NULL,
[joinType] [tinyint] NOT NULL,
[regDate] [datetime] NOT NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_league_team_user] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_league_team_user](
[idx] [int] IDENTITY(1,1) NOT NULL,
[teamIDX] [int] NULL,
[leagueIDX] [int] NULL,
[startDate] [int] NULL,
[teamName] [nvarchar](20) NULL,
[leaderIDX] [int] NULL,
[leagueStartPosition] [smallint] NULL,
[leaguePosition] [smallint] NULL,
[maxcount] [tinyint] NULL,
[cheerPoint] [int] NULL,
[currentRound] [tinyint] NULL,
[factionPoint] [int] NULL,
[factionType] [tinyint] NULL,
[regDate] [datetime] NULL,
[insertDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_level_playtime] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_level_playtime](
[idx] [int] IDENTITY(1,1) NOT NULL,
[userLevel] [int] NOT NULL,
[playTime] [bigint] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_mannerpoint] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_mannerpoint](
[idx] [int] IDENTITY(1,1) NOT NULL,
[playType] [int] NOT NULL,
[modeType] [int] NOT NULL,
[sub1Type] [int] NOT NULL,
[sub2Type] [int] NOT NULL,
[reportIDX] [int] NULL,
[reportNick] [varchar](20) NULL,
[reportpubIP] [varchar](15) NOT NULL,
[reportpriIP] [varchar](15) NOT NULL,
[receiveIDX] [nchar](10) NULL,
[receiveNick] [varchar](20) NULL,
[receivepubIP] [varchar](15) NOT NULL,
[roomInfo] [varchar](2000) NULL,
[chatInfo] [varchar](3000) NULL,
[note] [varchar](500) NULL,
[reason] [varchar](2000) NULL,
[flag] [tinyint] NOT NULL,
[resultType] [tinyint] NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_mannerpoint_sitevisit] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_mannerpoint_sitevisit](
[idx] [int] IDENTITY(1,1) NOT NULL,
[accountIDX] [int] NOT NULL,
[point] [smallint] NOT NULL,
[userIP] [varchar](15) NOT NULL,
[regDate] [datetime] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[log_tooni_migration] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log_tooni_migration](
[idx] [int] IDENTITY(1,1) NOT NULL,
[TooniIDX] [int] NOT NULL,
[TooniID] [varchar](32) NOT NULL,
[AccountIDX] [int] NOT NULL,
[RegDate] [datetime] NOT NULL,
CONSTRAINT [PK_log_tooni_migration] PRIMARY KEY CLUSTERED
(
[RegDate] ASC,
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Index [accountidx] Script Date: 5/4/2025 8:44:49 PM ******/
CREATE NONCLUSTERED INDEX [accountidx] ON [dbo].[log_data_clover]
(
[accountIDX] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object: Index [regDate] Script Date: 5/4/2025 8:44:49 PM ******/
CREATE NONCLUSTERED INDEX [regDate] ON [dbo].[log_data_clover]
(
[regDate] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
/****** Object: Index [NC_log_tooni_migration_AccountIDX] Script Date: 5/4/2025 8:44:49 PM ******/
CREATE NONCLUSTERED INDEX [NC_log_tooni_migration_AccountIDX] ON [dbo].[log_tooni_migration]
(
[AccountIDX] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object: Index [NC_log_tooni_migration_TooniID] Script Date: 5/4/2025 8:44:49 PM ******/
CREATE NONCLUSTERED INDEX [NC_log_tooni_migration_TooniID] ON [dbo].[log_tooni_migration]
(
[TooniID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
ALTER TABLE [dbo].[log_class_buytime] ADD CONSTRAINT [DF_log_class_buytime_classType] DEFAULT ((0)) FOR [classType]
GO
ALTER TABLE [dbo].[log_class_buytime] ADD CONSTRAINT [DF_log_class_buytime_buyTime] DEFAULT ((0)) FOR [buyTime]
GO
ALTER TABLE [dbo].[log_class_buytime] ADD CONSTRAINT [DF_log_class_buytime_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_class_rental_history] ADD CONSTRAINT [DF_log_class_rental_history_classType] DEFAULT ((0)) FOR [classType]
GO
ALTER TABLE [dbo].[log_class_rental_history] ADD CONSTRAINT [DF_log_class_rental_history_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_data_clover] ADD CONSTRAINT [DF_log_clover_friendIdx] DEFAULT ((0)) FOR [friendIDX]
GO
ALTER TABLE [dbo].[log_data_clover] ADD CONSTRAINT [DF_log_clover_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_event_marble] ADD CONSTRAINT [DF_log_event_marble_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_event_openbeta_coin] ADD CONSTRAINT [DF_log_event_openbeta_coin_flag] DEFAULT ((0)) FOR [flag]
GO
ALTER TABLE [dbo].[log_event_openbeta_coin] ADD CONSTRAINT [DF_log_event_openbeta_coin_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_guild_mark] ADD CONSTRAINT [DF_log_guild_mark_flag] DEFAULT ((0)) FOR [flag]
GO
ALTER TABLE [dbo].[log_guild_mark] ADD CONSTRAINT [DF_log_guild_mark_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_league_cheer] ADD CONSTRAINT [DF_log_league_cheer_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_info_user] ADD CONSTRAINT [DF_log_league_info_user_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_list] ADD CONSTRAINT [DF_log_league_list_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_list_user] ADD CONSTRAINT [DF_log_league_list_user_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_round_user] ADD CONSTRAINT [DF_log_league_round_user_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_team] ADD CONSTRAINT [DF_log_league_team_leagueStartPosition] DEFAULT ((0)) FOR [leagueStartPosition]
GO
ALTER TABLE [dbo].[log_league_team] ADD CONSTRAINT [DF_log_league_team_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_team_member] ADD CONSTRAINT [DF_log_league_team_member_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_team_member_user] ADD CONSTRAINT [DF_log_league_team_member_user_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_league_team_user] ADD CONSTRAINT [DF_log_league_team_user_insertDate] DEFAULT (getdate()) FOR [insertDate]
GO
ALTER TABLE [dbo].[log_level_playtime] ADD CONSTRAINT [DF_log_level_playtime_userLevel] DEFAULT ((0)) FOR [userLevel]
GO
ALTER TABLE [dbo].[log_level_playtime] ADD CONSTRAINT [DF_log_level_playtime_playTime] DEFAULT ((0)) FOR [playTime]
GO
ALTER TABLE [dbo].[log_level_playtime] ADD CONSTRAINT [DF_log_level_playtime_regDate] DEFAULT (getdate()) FOR [regDate]
GO
ALTER TABLE [dbo].[log_mannerpoint] ADD CONSTRAINT [DF_log_mannerpoint_flag] DEFAULT ((0)) FOR [flag]
GO
ALTER TABLE [dbo].[log_mannerpoint] ADD CONSTRAINT [DF_log_mannerpoint_resultType] DEFAULT ((0)) FOR [resultType]
GO
ALTER TABLE [dbo].[log_tooni_migration] ADD DEFAULT (getdate()) FOR [RegDate]
GO
/****** Object: StoredProcedure [dbo].[game_item_etc_get_self_index] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[game_item_etc_get_self_index]
(
@accountIDX int
)
AS
SELECT TOP 1 idx FROM userItemEtcDB WHERE accountIDX = @accountIDX ORDER BY idx DESC
GO
/****** Object: StoredProcedure [dbo].[log_data_clover_add] Script Date: 5/4/2025 8:44:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[log_data_clover_add]
(
@userIDX int
, @FriendIDX int
, @Type smallint
, @Count int
)
AS
SET NOCOUNT ON
-- 클로버 정보가 없을때 insert
INSERT INTO dbo.log_data_clover( accountIDX, friendIDX, eventType, CloverCount, regDate )
VALUES( @userIDX, @FriendIDX, @Type, @Count, GETDATE() );
GO
USE [master]
GO
ALTER DATABASE [LosaGame_log] SET READ_WRITE
GO
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+24
View File
@@ -0,0 +1,24 @@
-- LosaDev 2019: database users for the DB agent logins (db_owner, like the original service).
USE [LosaGame_log]
GO
IF USER_ID(N'lstggame') IS NULL CREATE USER [lstggame] FOR LOGIN [lstggame]
ALTER ROLE [db_owner] ADD MEMBER [lstggame]
GO
USE [Backup]
GO
IF USER_ID(N'lstggame') IS NULL CREATE USER [lstggame] FOR LOGIN [lstggame]
ALTER ROLE [db_owner] ADD MEMBER [lstggame]
GO
USE [LosaLogData]
GO
IF USER_ID(N'lstggame') IS NULL CREATE USER [lstggame] FOR LOGIN [lstggame]
ALTER ROLE [db_owner] ADD MEMBER [lstggame]
GO
IF USER_ID(N'lstglog') IS NULL CREATE USER [lstglog] FOR LOGIN [lstglog]
ALTER ROLE [db_owner] ADD MEMBER [lstglog]
GO
USE [LosaGame]
GO
IF USER_ID(N'lstggame') IS NULL CREATE USER [lstggame] FOR LOGIN [lstggame]
ALTER ROLE [db_owner] ADD MEMBER [lstggame]
GO
+8
View File
@@ -0,0 +1,8 @@
-- LosaDev 2019: the 15-character key the game server reads at start (define_encode_key,
-- game_encode_get_fix_key). setup-db.bat asks for it (ENCODE_KEY).
USE [LosaGame]
GO
IF LEN(N'$(ENCODE_KEY)') <> 15 RAISERROR('ENCODE_KEY must be 15 characters', 16, 1)
ELSE IF NOT EXISTS (SELECT 1 FROM dbo.define_encode_key WHERE encodeKey = '$(ENCODE_KEY)')
INSERT INTO dbo.define_encode_key (encodeKey, regDate) VALUES ('$(ENCODE_KEY)', GETDATE())
GO
+69
View File
@@ -0,0 +1,69 @@
-- LosaDev 2019: procedures the 2019 server calls (ls_query.ini ids 1, 136, 137, 139)
-- that no released DB script contains. Written for the testbed from the server code (DBClient.cpp).
-- Still missing on purpose: 197 game_item_extra_get_list_dev, 1500 SC_ERROR_LOG_ADD,
-- 2108 log_item_bonus_gold_set_add, 2207 game_block_hdd_serial_check (dev/log/anti-cheat only).
USE [LosaGame]
GO
IF OBJECT_ID(N'dbo.game_pingpong', N'P') IS NOT NULL DROP PROCEDURE dbo.game_pingpong
GO
-- id 1: DB agent keep-alive; the code says "a query that does not really exist"
CREATE PROCEDURE dbo.game_pingpong
AS
SET NOCOUNT ON
GO
IF OBJECT_ID(N'dbo.game_member_count', N'P') IS NOT NULL DROP PROCEDURE dbo.game_member_count
GO
-- id 136: OnSelectMemberConut - one LONG back, 0 = new account (the server then calls game_member_add)
CREATE PROCEDURE dbo.game_member_count
@userID varchar(12)
AS
SET NOCOUNT ON
SELECT COUNT(*) FROM dbo.userMemberDB WITH(NOLOCK) WHERE userID = @userID
GO
IF OBJECT_ID(N'dbo.game_member_add', N'P') IS NOT NULL DROP PROCEDURE dbo.game_member_add
GO
-- id 137: OnInsertMember(privateID, publicID) - first login of a publisher account creates the game account
CREATE PROCEDURE dbo.game_member_add
@userID varchar(12),
@nickName varchar(20)
AS
SET NOCOUNT ON
IF EXISTS (SELECT 1 FROM dbo.userMemberDB WITH(NOLOCK) WHERE userID = @userID) RETURN
DECLARE @ret int
EXEC dbo.web_member_add @userID, @nickName, '', '', 0, 0, 0, 0, '127.0.0.1', @ret OUTPUT
GO
IF OBJECT_ID(N'dbo.game_create_nickname', N'P') IS NOT NULL DROP PROCEDURE dbo.game_create_nickname
GO
-- id 139: OnUpdateFirstPublicID(accountIDX, newNick)
CREATE PROCEDURE dbo.game_create_nickname
@accountIDX int,
@nickName varchar(20)
AS
SET NOCOUNT ON
UPDATE dbo.userMemberDB SET nickName = @nickName WHERE accountIDX = @accountIDX
GO
-- id 11 game_game_get_data: the released script returns cpID/cpUNIQ (channeling columns), but the game server only
-- reads them when the locale uses channeling IDs (Korea). The Indonesia locale expects the same row without them.
ALTER PROCEDURE [dbo].[game_game_get_data]
(
@userID varchar(12)
)
As
SET NOCOUNT ON
DECLARE @CURRENTDATE DATETIME
DECLARE @CONNECTDATE DATETIME
SET @CURRENTDATE = GETDATE();
SET @CONNECTDATE = ( SELECT conndate FROM dbo.userGameDB WHERE accountIDX IN ( SELECT accountIDX FROM dbo.userMemberDB WHERE userID = @userID ))
IF( @CURRENTDATE < @CONNECTDATE )
SET @CONNECTDATE = @CURRENTDATE
SELECT a.accountIDX, b.userID, b.nickName, a.userState, a.gameMoney
, a.conn_count, @CONNECTDATE, a.userLevel, a.userEXP
, b.eventType, isNull(c.class,0) as 'class', b.joinType, b.regDate, a.regionType
, a.rencpoint, a.renspoint, isNull(c.region,0) as 'region', b.cpType
, b.limitType, b.limitDate, a.userFishingLevel, a.userFishingEXP
, a.refillData, a.userExcavationLevel, a.userExcavationEXP, a.userHerocEXP, a.userHerosEXP, a.practice
FROM userGameDB a WITH( NOLOCK )
JOIN userMemberDB b WITH( NOLOCK ) ON a.accountIDX = b.accountIDX
LEFT JOIN userRankingDB c WITH( NOLOCK ) ON a.accountIDX = c.accountIDX
WHERE b.userID = @userID
GO
+21
View File
@@ -0,0 +1,21 @@
-- First regular tournament (Faction War / LS Cup panel). The main server only continues a row that exists;
-- nothing creates the first one. leagueType 1 = TYPE_REGULAR, leagueState 1 = STATE_TEAM_APP, accountIDX 0 = no owner.
-- Dates are YYMMDDHHMM in a DWORD (Help::ConvertCTimeToDate). Since 2022 that is above the int range, so the
-- int columns hold the wrapped value; the server reads the same bits back as a DWORD.
-- Starts on the last Monday 03:00 and runs next_tournament_hour (336) hours, like sp2_tournament_regular.ini.
USE [LosaGame]
GO
IF NOT EXISTS (SELECT 1 FROM dbo.userLeagueListDB WHERE leagueType = 1)
BEGIN
DECLARE @s datetime, @e datetime, @a bigint, @b bigint
SET @s = DATEADD(hour, 3, DATEADD(day, -(DATEDIFF(day, 0, GETDATE()) % 7), DATEDIFF(day, 0, GETDATE())))
SET @e = DATEADD(hour, 336, @s)
SET @a = CAST(YEAR(@s) % 100 AS bigint) * 100000000 + MONTH(@s) * 1000000 + DAY(@s) * 10000 + DATEPART(hour, @s) * 100
SET @b = CAST(YEAR(@e) % 100 AS bigint) * 100000000 + MONTH(@e) * 1000000 + DAY(@e) * 10000 + DATEPART(hour, @e) * 100
IF @a > 2147483647 SET @a = @a - 4294967296
IF @b > 2147483647 SET @b = @b - 4294967296
INSERT INTO dbo.userLeagueListDB (accountIDX, startDate, endDate, leagueType, leagueState, regDate)
VALUES (0, @a, @b, 1, 1, GETDATE())
END
SELECT idx, startDate, endDate, leagueType, leagueState FROM dbo.userLeagueListDB
GO
+48
View File
@@ -0,0 +1,48 @@
# Database setup (2019)
Creates the four databases the 2019 servers use, with the original names:
| Database | Used by |
|---|---|
| `LosaGame` | game data and accounts (DB agent `ls_dbagent_game`) |
| `LosaGame_log` | game-side logs, written by procedures in `LosaGame` |
| `LosaLogData` | log server data (DB agent `ls_dbagent_logdb`) |
| `Backup` | stays empty: game procedures such as `game_practice_rank_reward` and `game_region_backup_point` create their own tables in it |
The schema is the **2021 release's** full scripts. The 2019 release's own scripts (`sql\20120504` + the patches in `DB\`) are a 2012 base and lack 212 of the 401 procedures the 2019 server calls; the 2021 schema matches all but a few, which `07_losadev_2019_procs.sql` adds (`game_member_count`, `game_member_add`, `game_create_nickname`, `game_pingpong`, the Indonesia `game_game_get_data`).
Tested 2026-11-07 on SQL Server 2022 Express: every script runs without an error; LosaGame has 134 tables / 1065 procedures, LosaGame_log 20 / 2, LosaLogData 67 / 81; both logins connect, the game login can create tables in `Backup`; backup and restore of all four work.
## Needs
- SQL Server 2019 or newer (Express is enough) with **SQL Server and Windows authentication** (mixed mode).
- `sqlcmd` on PATH.
- Recommended: instance collation `Korean_Wansung_CI_AS`, like the original service.
## Setup
```bat
setup-db.bat .\SQLEXPRESS
```
It asks for the **DB agent password** (SQL logins `lstggame` and `lstglog`; put it in `PW=` of the `ls_dbagent.ini` files in `server-config\`) and the **encode key** (15 characters, `define_encode_key`). `set DB_COLLATE=Korean_Wansung_CI_AS` before running forces a collation. Logs go to `logs\`.
| Script | Does |
|---|---|
| `00_create_databases.sql` | creates `LosaGame`, `LosaGame_log`, `LosaLogData`, `Backup` |
| `01_logins.sql` | SQL logins `lstggame`, `lstglog` |
| `02_LosaGame_log.sql`, `03_LosaLogData.sql`, `04_LosaGame.sql` | the 2021 release schema (only the `CREATE DATABASE` block taken out) |
| `05_users.sql` | `db_owner` users for the logins |
| `06_encode_key.sql` | the encode key |
| `07_losadev_2019_procs.sql` | the procedures the 2019 server needs on top of the 2021 schema |
| `08_first_tournament.sql` | the first tournament row (Faction / LS Cup screens) |
| `optional\test-accounts.sql` | test accounts `tester1` and `gmtest1` (Indonesia IDs need 6-12 characters), run by hand |
## Backup and restore
```bat
backup.bat D:\LosaBackup .\SQLEXPRESS
restore.bat 20261107_1400 D:\LosaBackup .\SQLEXPRESS
```
`backup.bat` writes `<database>_<yyyyMMdd_HHmm>.bak` for all four databases (online). `restore.bat` asks first and replaces all four: **stop every server before restoring**. It restores to the paths stored in the backup (same server); on another server use `RESTORE DATABASE ... WITH MOVE` by hand.
+9
View File
@@ -0,0 +1,9 @@
@echo off
rem LosaDev 2019: backup.bat [folder] [server] (defaults: D:\LosaBackup, .\SQLEXPRESS)
setlocal
set DIR=%~1
if "%DIR%"=="" set DIR=D:\LosaBackup
set SRV=%~2
if "%SRV%"=="" set SRV=.\SQLEXPRESS
if not exist "%DIR%" mkdir "%DIR%"
sqlcmd -S "%SRV%" -E -b -v BACKUP_DIR="%DIR%" -i "%~dp0backup.sql"
+26
View File
@@ -0,0 +1,26 @@
-- LosaDev 2019: full backup of LosaGame, LosaGame_log, LosaLogData and Backup.
-- sqlcmd -S <server> -E -v BACKUP_DIR="D:\LosaBackup" -i backup.sql (or backup.bat)
-- One file per database: <db>_yyyyMMdd_HHmm.bak in BACKUP_DIR (the folder must exist and the SQL
-- Server service account needs write access). Online backup: the servers may keep running.
USE [master]
GO
SET NOCOUNT ON
DECLARE @dir nvarchar(400) = N'$(BACKUP_DIR)', @stamp nvarchar(20) = FORMAT(GETDATE(), 'yyyyMMdd_HHmm'), @db sysname, @file nvarchar(600)
IF RIGHT(@dir, 1) = N'\' SET @dir = LEFT(@dir, LEN(@dir) - 1)
DECLARE d CURSOR LOCAL FAST_FORWARD FOR SELECT v FROM (VALUES (N'LosaGame'), (N'LosaGame_log'), (N'LosaLogData'), (N'Backup')) t(v)
OPEN d
FETCH NEXT FROM d INTO @db
WHILE @@FETCH_STATUS = 0
BEGIN
IF DB_ID(@db) IS NOT NULL
BEGIN
SET @file = @dir + N'\' + @db + N'_' + @stamp + N'.bak'
BACKUP DATABASE @db TO DISK = @file WITH INIT, CHECKSUM, STATS = 25
PRINT 'backup ' + @db + ' -> ' + @file
END
ELSE PRINT 'skip ' + @db + ' (does not exist)'
FETCH NEXT FROM d INTO @db
END
CLOSE d
DEALLOCATE d
GO
+15
View File
@@ -0,0 +1,15 @@
-- LosaDev 2019 (optional): test accounts and seed rows (run after the schema scripts).
-- The Indonesia build only accepts IDs of 6-12 letters/digits/-/_, so "test1" is too short: the IDs are tester1 / gmtest1.
-- Passwords are stored for reference only: with TestMode=1 the billing server does not check them.
-- gmtest1's nickname GMTest1 is listed in ls_gamesvr\config\sp2_developerID.ini (developer = GM rights).
-- Any other 6-12 character ID also works: the first login creates the account (game_member_add).
USE [LosaGame]
GO
SET NOCOUNT ON
DECLARE @ret int
IF NOT EXISTS (SELECT 1 FROM dbo.userMemberDB WHERE userID = 'tester1')
EXEC dbo.web_member_add 'tester1', 'Tester1', 'test1234', '', 0, 0, 0, 0, '127.0.0.1', @ret OUTPUT
IF NOT EXISTS (SELECT 1 FROM dbo.userMemberDB WHERE userID = 'gmtest1')
EXEC dbo.web_member_add 'gmtest1', 'GMTest1', 'test1234', '', 0, 0, 0, 0, '127.0.0.1', @ret OUTPUT
SELECT accountIDX, userID, nickName FROM dbo.userMemberDB WHERE userID IN ('tester1', 'gmtest1')
GO
+12
View File
@@ -0,0 +1,12 @@
@echo off
rem LosaDev 2019: restore.bat <stamp> [folder] [server] stamp = yyyyMMdd_HHmm of the backup files
rem Stop every game server first. The three databases are replaced.
setlocal
if "%~1"=="" echo Usage: restore.bat ^<yyyyMMdd_HHmm^> [folder] [server] & exit /b 1
set DIR=%~2
if "%DIR%"=="" set DIR=D:\LosaBackup
set SRV=%~3
if "%SRV%"=="" set SRV=.\SQLEXPRESS
choice /m "Replace LosaGame, LosaGame_log, LosaLogData and Backup on %SRV% with the %~1 backup"
if errorlevel 2 exit /b 1
sqlcmd -S "%SRV%" -E -b -v BACKUP_DIR="%DIR%" STAMP="%~1" -i "%~dp0restore.sql"
+30
View File
@@ -0,0 +1,30 @@
-- LosaDev 2019: restores LosaGame, LosaGame_log, LosaLogData and Backup from backup.sql files.
-- sqlcmd -S <server> -E -v BACKUP_DIR="D:\LosaBackup" STAMP="20261107_1400" -i restore.sql (or restore.bat)
-- STAMP = the yyyyMMdd_HHmm part of the file names. STOP ALL GAME SERVERS FIRST: each database is
-- set to single user and replaced. The files go back to the paths stored in the backup, so restore
-- on the same server; on another server use RESTORE ... WITH MOVE by hand (see README.md).
USE [master]
GO
SET NOCOUNT ON
DECLARE @dir nvarchar(400) = N'$(BACKUP_DIR)', @stamp nvarchar(20) = N'$(STAMP)', @db sysname, @file nvarchar(600), @sql nvarchar(400)
IF RIGHT(@dir, 1) = N'\' SET @dir = LEFT(@dir, LEN(@dir) - 1)
DECLARE d CURSOR LOCAL FAST_FORWARD FOR SELECT v FROM (VALUES (N'LosaGame'), (N'LosaGame_log'), (N'LosaLogData'), (N'Backup')) t(v)
OPEN d
FETCH NEXT FROM d INTO @db
WHILE @@FETCH_STATUS = 0
BEGIN
SET @file = @dir + N'\' + @db + N'_' + @stamp + N'.bak'
IF DB_ID(@db) IS NOT NULL
BEGIN
SET @sql = N'ALTER DATABASE ' + QUOTENAME(@db) + N' SET SINGLE_USER WITH ROLLBACK IMMEDIATE'
EXEC (@sql)
END
RESTORE DATABASE @db FROM DISK = @file WITH REPLACE, CHECKSUM
SET @sql = N'ALTER DATABASE ' + QUOTENAME(@db) + N' SET MULTI_USER'
EXEC (@sql)
PRINT 'restored ' + @db + ' from ' + @file
FETCH NEXT FROM d INTO @db
END
CLOSE d
DEALLOCATE d
GO
+30
View File
@@ -0,0 +1,30 @@
@echo off
rem LosaDev 2019: creates LosaGame, LosaGame_log, LosaLogData and Backup and fills them.
rem Usage: setup-db.bat [server] (default .\SQLEXPRESS; Windows login with sysadmin rights)
rem Needs sqlcmd (SQL Server command line tools) on PATH. Asks for the DB agent password.
rem Logs go to logs\. Existing databases are kept; scripts that already ran give "already exists" errors.
setlocal
cd /d "%~dp0"
set SRV=%~1
if "%SRV%"=="" set SRV=.\SQLEXPRESS
if "%DB_COLLATE%"=="" set DB_COLLATE=DEFAULT
set /p DB_PASSWORD=Password for the DB agent logins (same as PW= in ls_dbagent.ini):
set /p ENCODE_KEY=Encode key, 15 characters:
if "%DB_PASSWORD%"=="" echo No password given. & exit /b 1
if not exist logs mkdir logs
call :run 00_create_databases.sql
call :run 01_logins.sql
call :run 02_LosaGame_log.sql
call :run 03_LosaLogData.sql
call :run 04_LosaGame.sql
call :run 05_users.sql
call :run 06_encode_key.sql
call :run 07_losadev_2019_procs.sql
call :run 08_first_tournament.sql
findstr /b /c:"Msg " logs\*.log >nul && (echo Some statements failed: search logs\*.log for "Msg ".) || echo Done, no errors.
exit /b 0
:run
echo running %1
sqlcmd -S "%SRV%" -E -I -f 65001 -v DB_COLLATE="%DB_COLLATE%" DB_PASSWORD="%DB_PASSWORD%" ENCODE_KEY="%ENCODE_KEY%" -i "%1" -o "logs\%~n1.log"
exit /b 0