SQL Server – Build a full backup image, deliver clones in containers after applying transaction log backups to get point in time clones.

Point in time SQL Server database cloning for fixed instances and containers

Windocks supports delivery of point in time SQL Server environments through application of transaction log backups to both Windocks SQL Server containers and existing fixed SQL Server instances. For instructions contact support@windocks.com 

dockerfile

# This Dockerfile supports delivery of SQL Server database clones to both fixed SQL Server instances and containers.
FROM mssql-2019

# Transaction log backups are read from a volume-mounted file path, e.g.: D:\dbbackups\updates\<dbname>
# Whether there is one or multiple databases, each database's transaction log backups must reside
# in a subfolder named after the database, within the same root path (e.g.: D:\dbbackups\updates\<dbname>).
# OrderToApply controls the sequence in which backup files are applied. Valid values:
#   CreateTimeAsc | CreateTimeDesc | AccessTimeAsc | AccessTimeDesc | WriteTimeAsc | WriteTimeDesc | NameAsc | NameDesc
ENV RUNTIME_TRANSACTIONLOG_BACKUPS_ONLY "BackupDirectory|D:\dbbackups\updates OrderToApply|NameAsc PointInTime|True"

# Uncomment the lines below to run a custom SQL script at container startup.
#COPY script.sql .
#RUN script.sql

# Setting this to 1 instructs Windocks to use the lines below while configuring containers created from this image.
ENV USE_DOCKERFILE_TO_CREATE_CONTAINER=1

# Creates a network share for fixed instances support
RUN SourceClone_Windocks NetworkShareName|$ContainerId NetworkSharePath|C:\Windocks\data\$ContainerId NetworkShareUsers|Everyone

# Attaches the cloned database(s) to the target SQL Server instance specified by the user
# via the web application or command line. Do not modify this line — the $-prefixed placeholders
# are automatically replaced with user-supplied values at runtime.
# Note: The target SQL Server instance must have a SQL SA account with sysadmin privileges.
# The SA account is used when provisioning to the fixed instance.

RUN TargetAttach_SqlWindows InstanceName|$SqlInstanceName SqlUserName|$SqlInstanceUserName SqlPassword|$SqlInstancePassword

# Defines the full backup source for the primary database to be cloned.
# For images with multiple databases, add one SETUPCLONING FULL line per database.
SETUPCLONING FULL dbname d:\dbbackups\dbname.bak
# SETUPCLONING FULL dbname2 e:\dbbackups\dbname2.bak

# Enables point-in-time recovery at clone time. The point-in-time value is set at runtime
# and must follow this format: YYYY-MM-DD HH:MM:SS  (e.g., 2017-07-11 10:29:38)
ENV STARTENV_POINT_IN_TIME_ENDENV=1

# Set this to skip applying any transaction log backups during cloning.
# Leave the point-in-time variable blank, or set this variable to "yes" to disable log replay entirely.
ENV STARTENV_DO_NOT_APPLY_LOG_BACKUPS_ENDENV=1