# Automating the Manager features

All actions usually performed in the Manager user interface (until the distribution of a model), can be automated in a scripting file. All sources and targets supported by the Manager are also supported in the script file.

## About this task

The actions to be automated in the script file are the following:

* starting and stopping database journalization,

* creating and deleting an environment,

* creating and deleting a model,

* adding and deleting tables,

* creating and deleting a target,

* starting, stopping and terminating the distribution of a model,

* performing a load recovery on the distribution.

## Procedure

1. To create the script file, open a .txt file.
2. Feed it according to the following commands and their syntax:

   Information noteNote: You can add as many commands as you like in the same script file (for example, connecting to various source databases and creating various distributions is possible). You can also create one script file for each source type. It depends on your needs.
   | Command | Description | Details and Syntax |
   | --- | --- | --- |
   | : comment line |  | ```<br>:this is a comment line<br>```<br><br><br>or<br><br>```<br>: this is a comment line<br>``` |
   | connect source | To connect the source database | Type entry is one among the databases supported as source<br>(AS400, MS SQL Server, Oracle, OpenEdge,<br>PostgreSQL, MySQL, MariaDB).<br><br>Three<br>different commands are used:<br><br><ul> <li>For <span>AS400</span> IBMi source:												<pre><code><pre><code><code>connect IpAddress/AS400/</code></code></pre></code></pre> </li> <li>For <span>MS SQL Server</span> and <span>Oracle</span> sources:												<pre><code><pre><code><code>connect IpAddress/Type/Instance</code></code></pre></code></pre> </li> <li>For <span>MariaDB</span>, <span>MySQL</span>, <span>PostgreSQL</span>												and <span>OpenEdge</span>												sources:<pre><code><pre><code><code>connect IpAddress/Type/DB_Name</code></code></pre></code></pre> </li> </ul> |
   | start journalization |  | ```<br>start-journalisation<br>Database = <database_name><br>StoragePath = <storage_path><br>end-journalisation<br>```<br><br>where storage\_path is the folder located on<br>the same machine as the engine, used for the storage of .JRN<br>files. |
   | select-env | To select an environment | Use this command only if you want to use an environment<br>that is already created in the Manager.<br><br>```<br>select-env envid<br>``` |
   | create env | To create and select an environment<br><br><br>Default value is used if no parameter is<br>specified | ```<br>create-env envid<br>	EnvType	:=	2<br>				:0 = Production	'default<br>				:1 = Test<br>				:2 = Training<br>				:3 = Model<br>				:4 = Deployment<br>	Description    :=	SFEnvirt Training 01<br>	Hold	    :=	0<br>				:0 = False	     :default<br>				:1 = True<br>	SrcId	    :=	S01<br>	Tempo	    :=	1<br>	Retry	    :=	5<br>end-create<br>``` |
   | create metadata | To create metadata for this environment | Mainly for the JSON variables used for streaming sources (Kafka, Kinesis,<br>Snowflake). The JSON script is then included in the<br>create model<br>command.<br><br>```<br>select-env envid<br>create-metadata<br>	#variable1#	:=	metavalue1<br>	#variable2#	:=	metavalue2<br>	#variable3#       :=      metavalue3<br>end-create<br>``` |
   | select model | To select a model | ```<br>select-env envid<br>select-model grpid<br>``` |
   | create model | To create and select a model<br><br><br>Default value is used if no parameter is<br>specified | AS400 source<br><br>```<br>select-env envid<br>create-model grpid<br><br>GrpType         :=   0<br>			:0 = Journal<br>			:1 = Extract<br>Description     :=   SFo-Replication a l'identique<br>iASPgroup       :=   *NONE<br>LibJrn          :=   DD_TRAING<br>JrnName         :=   JOURNAL<br>ManualDistrib   :=   0<br>			:0 = False		:default<br>			:1 = True<br>AllMembers      :=   0<br>			:0 = False		:default<br>			:1 = True<br>AccesMode       :=   3<br>			:0 = Auto		 :default<br>			:1 = RRN<br>			:2 = Index Key<br>			:3 = SQL<br>			:4 = Backup<br>OrpheanMgt      :=   0<br>			:0 = False		:default<br>			:1 = True<br>ContError       :=   0<br>			:0 = False		:default<br>			:1 = True<br>Repair          :=   1<br>			:0 = No<br>			:1 = Yes		  :default<br>			:2 = Skip<br>			:3 = Yes with trace<br>DDLchange       :=   1<br>			:0 = No		<br>			:1 = Ignore<br>			:2 = Yes		<br>			:3 = Yes Alter no Drop	:default<br>			:4 = Yes Alter with Drop<br>Truncate        :=   1<br>			:0 = No<br>			:1 = Yes		  :default<br>			:2 = Ignore<br>RGZPFM          :=   2<br>			:0 = No<br>			:1 = Yes<br>			:2 = Ignore		:default<br>ADDPFM          :=   2<br>			:0 = No<br>			:1 = Yes<br>			:2 = Ignore		:default<br>RMVMBR          :=   2<br>			:0 = No<br>			:1 = Yes<br>			:2 = Ignore		:default<br>DLTF            :=   0<br>			:0 = No		    :default<br>			:1 = Yes<br>NullProcess     :=   0<br>			:0 = No		    :default<br>			:1 = Yes<br>DateAschar      :=   0<br>			:0 = No		    :default<br>			:1 = Yes<br>MetaScript      :=   Begin<br>script<br>MetaScript      :=   End<br><br>end-create<br>```<br><br>Other sources<br><br>```<br>create-model grpid<br>GrpType         :=   0<br>			:0 = Journal<br>			:1 = Extract<br>Description     :=   SFo-Replication a l'identique<br>DataBase        :=   DD_TRAINING<br>ManualDistrib   :=   0<br>			:0 = False		:default<br>			:1 = True<br>AllMembers      :=   0<br>			:0 = False		:default<br>			:1 = True<br>AccesMode       :=   3<br>			:0 = Auto		 :default<br>			:1 = RRN<br>			:2 = Index Key<br>			:3 = SQL<br>			:4 = Backup<br>OrpheanMgt      :=   0<br>			:0 = False		:default<br>			:1 = True<br>ContError       :=   0<br>			:0 = False		:default<br>			:1 = True<br>Repair          :=   1<br>			:0 = No<br>			:1 = Yes		  :default<br>			:2 = Skip<br>			:3 = Yes with trace<br>DDLchange       :=   1<br>			:0 = No		<br>			:1 = Ignore<br>			:2 = Yes		<br>			:3 = Yes Alter no Drop	:default<br>			:4 = Yes Alter with Drop<br>Truncate        :=   1<br>			:0 = No<br>			:1 = Yes		   :default<br>			:2 = Ignore<br>NullProcess     :=   0<br>			:0 = No		    :default<br>			:1 = Yes<br>DateAschar      :=   0<br>			:0 = No		    :default<br>			:1 = Yes<br>MetaScript      :=   Begin<br>script<br>MetaScript      :=   End<br>end-create<br>``` |
   | select-table | To select a table | ```<br>select-env envid<br>select-model grpid<br>select-table tableid<br>``` |
   | add-table | To add a new table to the model selected | The Id is the unique identifier (numeric from 1 to 9999999999) of the table in<br>this model.<br><br>Thanks to this Id, a table can be<br>added more than one time but with different<br>identifiers.<br><br><br>AS400<br>source<br><br>```<br>select-env envid<br>select-model grpid<br>add-table Library FileName [TargetTableName] [Id:nn]<br><br>```<br><br>Other<br>sources<br><br>```<br>select-env envid<br>select-model grpid<br>add-table TableName [TargetTableName][Id:nn]<br><br>``` |
   | select target |  | ```<br>select-env envid<br>select-target tgtid<br>``` |
   | create target | To create and select a target | ```<br>select-env envid<br>create-target tgtid<br>Description	  :=   My DD machine<br>NewSourceId	  :=<br>				: blank is default<br>TargetType	   :=   1<br>				: 0 = IBM I<br>				: 1 = Windows		:default	<br>	Hold	   :=  0<br>				:0 = False		   :default<br>				:1 = True<br>	TargetName    :=  MyVM<br>	TargetAdress  :=  192.168.0.0<br>end-create<br>``` |
   | distribute model | To distribute the model to the target | ```<br>select-env envid<br>select-model grpid<br>select-target tgtid<br>distribute<br>	Hold            :=	0<br>				:0 = False		:default<br>				:1 = True<br>	scheduled       :=	0<br>				:0 = False		:default<br>				:1 = True<br>	TgtBDType       :=	0<br>				:0 =	IBMi<br>				:1 =	SQL Server<br>'2 = Oracle ODBC<br>				:5 = ODBC<br>				:8 = PostgreSQL<br>				:9 = Text<br>				:A = MySQL<br>				:B = DB2 LUW<br>				:C = XML<br>				:D = SyBase<br>				:E = Oracle OCI<br>				:F = SQL Server Bi-Directional<br>				:G = OpenEdge<br>				:H = SQLite<br>				:J = MySQL Latin<br>				:K = MySQL Native<br>				:L = PostgreSQL Native<br>				:M = SQLite NAtive<br>				:N = GreenPlum<br>				:O = Netezza<br>				:P = Vectowise MicroBatch<br>				:Q = VectorWise<br>				:R = NuoDB<br>				:S = Altibase<br>				:T = Iseries Access<br>				:V = Kafka<br>				:k = Kinesis	<br>				:W = Hana<br>				:X = Teradata	<br>				:Y = SalesForce<br>				:Z = MariaDB	<br>				:b = MariaDB Latin	<br>				:c = MariaDB Native<br>				:d = Azure SQL	<br>				:e = Azure Event Hub<br>				:g = Azure Service Bus<br>				:i = SnowFlake<br>	UseLibName      :=	0<br>				:0 = FileName		:default<br>				:1 = BDName_FileName<br>				:2 = BDName..FileName or BD.FileName<br>	TargetDB        :=	MyDatabase<br>	LoadByFlatFile  :=   0<br>				:0 = False		:default<br>				:1 = True<br>	PathForFlatFile :=<br>#if Kinesis or kafka or servicebus or eventhub Target<br>	Format           :=  J			:default<br>'J = Json<br>'A = Avro<br>'F = Fixed<br>'D = Delimited<br>	FieldNameOn1st   :=  0<br>				:0 = False		:default<br>				:1 = True<br>FieldSep         :=  ;<br>				:tab = tabulation<br>				:; = semicolon		:default<br>				:, = colon<br>				: … 1 character<br>	TextSep         :=  "<br>				:1 character<br>	LineSep          :=  2<br>				:1 = <CR><br>				:2 = <CR><LF>		'default<br>				:3 = <LF><br>				:4 = ;<br>				:5 = ,<br>				:6 = tabulation<br>				:7 = nothing<br>	DateFormat       :=  2<br>'0 = DMY<br>'1 = MDY<br>'2 = YMD			'default<br>'3 = YDM<br>'4 = DYM<br>'5 = MYD<br>	YearIn4Digits    :=  1<br>				:0 = False		<br>				:1 = True		:default<br><br>	DateDelimiter    :=  /			:default<br>				1 character<br>	TimeDelimiter    :=  :			:default<br>				1 character<br>	DecimalSep       :=  .			:default<br>				1 character<br>	kdsConnectString    :=  region=eu-west-3;<br>				accesskey={0B733EDD1CF71};<br>				secretkey={0B733EDD1CF71}<br>#elseif SnowFlake Target<br>	sfAccount         :=  AB65262.west-europe.azure<br>	sfConnectString   :=  DSN=SnowFlakes;UID=gammadev;<br>				PWD={0B733EDD1CF71};<br>				CodePage=e297UTF8.cpg;<br>	sfPathForTextFile :=  D:\DD_FILE\AS400\M3P<br>	sfCommandFile     :=  LoadData.cmd %s %s 1<br>	sfMaxRecord       :=  0<br>	sfMaxTime         :=  5<br>#else<br>	ConnectString     :=   DSN=…<br>#endif<br>#endif<br>	Planning          :=   000..000<br>				sequence of 168 digits (0 or 1)<br>				for the 168 hours of a week with<br>				0 = inactive, 1=active.<br>The first digit represents Monday from 0 AM to 1 AM<br>	RecoveryType      :=<br>				:Blank is nothing<br>				:C = Load<br>				:P = Sequence<br>	CaseSensitive     :=    0<br>				:0 = False		:default<br>				:1 = True<br>	CacheSize         :=    0<br>				:0 = 32Ko		:default<br>				:1 = 128K0<br>				:2 = 256Ko = 128*2<br>				:3 = 512Ko = 256*2<br>				..<br>				:7 = 8Mo<br>#if AS400 source<br>	RecoveryLib        :=<br>#endif<br>	RecoveryReceiver   :=<br>Sequence           :=<br>	end-distribute<br>``` |
   | change-distributed-table | To change the properties of the distributed table | First, use the selection commands:<br><br>```<br>select-model grpid<br>select-target tgtid<br>```<br><br><br>Then, change the properties of the distributed table:<br><br>```<br>change-distributed-table ficid TargetDBName TargetTableName<br>```<br><br>In case you want to change only the target table<br>name,<br>enter:<br><br>```<br>change-distributed-table ficid default TargetTableName<br>``` |
   | add query to table | To add the query to the selected table<br><br>Information noteNote: Only for NT sources. | First, use the selection<br>commands:<br><br>```<br>select-env envid<br>select-model grpid<br>select-table tableid<br>```<br><br>Then add the query to the table:<br><br>```<br>begin-script-where<br>:Some query after where clause<br>	SALESNUM = '1' AND PROMOKEY > 10<br>end-script-where<br>``` |
   | add transformation to the table | To add the transformation to the selected table | First, use the selection commands:<br><br>```<br>select-env envid<br>select-model grpid<br>select-table tableid<br>```<br><br><br>Then add the transformation to the<br>table:<br><br>```<br>begin-transformation<br>DCL O.SALESNUM Char 20 NULL Rtrim KEYORDER 1<br>DCL O.PROMOKEY Numeric 10,0 NULL Same<br><br>if I.SALESNUM = '1' Then<br>O.PROMOKEY = 1<br>O.SALESNUM = I.SALESNUM<br>Endif<br>end-transformation<br>```<br><br>DCL lines are the default<br>ones. They will appear in the list if no other declaration<br>is entered.<br><br><br>If you want to add another DCL than the<br><br>default ones, you can write it in the transformation block.<br><br>The default DCL lines are automatically removed from the<br>list and only your new lines are taken into account.<br><br>Information noteNote: Between begin-transformation and<br>end-transformation, comments are<br><br>marked with /\* only. |
   | stop distribution | To stop the distribution of the model | ```<br>select-env envid<br>select-target tgtid<br>stop-distribution grpid<br>``` |
   | kill distribution | To terminate the distribution of a model | ```<br>select-env envid<br>select-target tgtid<br>kill-distribution grpid<br>``` |
   | delete distribution | To delete the distribution of a model | ```<br>select-env envid<br>select-target tgtid<br>delete-distribution grpid<br>``` |
   | delete target | To delete a target | ```<br>select-env envid<br>delete-target tgtid<br>``` |
   | delete model | To delete a model | ```<br>select-env envid<br>delete-model grpid<br>``` |
   | delete table | To delete a table | ```<br>select-env envid<br>select-model grpid<br>delete-table tableid<br>``` |
   | delete environment | To delete an environment | ```<br>delete-env envid<br>``` |
   | stop journalization | To stop journalizing a database | ```<br>dejournalise dbid<br>``` |
3. Save the file.
4. Launch a command prompt and enter the following commands:

   &gt;cd TalendChangeDataCaptureDestinationPath. Press Enter.

   DDmanager -cicd "ScriptFilePath". Press Enter.

## Results

Distributions are created as they were declared in the script file.

If you want to view the result: launch the Manager and subscribe to the source, then connect to it. For more information, see [Managing sources subscription and connection](https://help.qlik.com/talend/en-US/change-data-capture-user-guide/7.3/managing-sources). To start the replication process, follow [Operating and supervising a replication](https://help.qlik.com/talend/r/en-US/7.3/change-data-capture-user-guide/operation-of-replication) section.

To check the logs after the start of the script, open DDMGRAUTO.log file located in DestinationPath repository (the same repository as the Manager .exe file).

To plan when to launch all replications, you can configure the Scheduler (see [Starting Replications Automatically](https://help.qlik.com/talend/r/en-US/7.3/change-data-capture-user-guide/starting-replications-automatically)).

### In this section

* [Script file samples](https://help.qlik.com/talend/en-US/change-data-capture-user-guide/7.3/script-file-samples)