snapshot
command
The snapshot
command captures the current state of the URL database, which is the target database.
The snapshot
command has two modes:
- When run without options, it gathers the current state of the database and shows a text-based version of the schema to STDOUT.
- When run with the
--snapshotFormat=JSON
option, it creates a JSON file that represents the current state of the URL database. Alternatively, you can have a YAML-based output by using the--snapshotFormat=yaml
attribute.
Uses
The snapshot
command is typically used when you want to see changes in your target database or keep a record of your current database state.
The snapshot can be used in the diff command or diffChangeLog command.
Note: It is best practice to use the --snapshotFormat=JSON
option for the diff
and diffChangeLog
commands. Otherwise, you will get only a text report of your target database. This text report cannot be used for comparison in the future.
It can also be used to compare:
- A previous database state to an online database.
- A previous database state to another snapshot.
Note: Running a diff
command by using at least one snapshot.json
file is faster than using a diff
command with two online databases. However, keep in mind that a snapshot will no longer reflect the current state of the database if the database is changed with the update
command or if it is changed manually.
Running the snapshot
command
To run the snapshot command, you need to specify your driver, class path, and URL in your liquibase.properties
file. For more information, see Creating and configuring a liquibase.properties file. You can also specify these properties in your command line.
Then run the snapshot
command:
liquibase snapshot
Note: To create a JSON file, add the --snapshotFormat=json
attribute while running the command:
liquibase --outputFile=mySnapshot.json snapshot --snapshotFormat=json
Note: Enter the name of the output file that you want to use in place of mySnapshot.json
. Additionally, include --snapshotFormat=json
to create a file in a JSON format.
snapshot
global attributes
Attributes | Definition | Requirement |
---|---|---|
--changeLogFile
|
The root changelog | Required |
--username
|
The database username | Required |
--password
|
The database password | Required |
--url
|
The JDBC database connection | Required |
|
Specifies the file path to where the snapshot JSON or YAML will be written | Optional |
* If not specified, a JSON or YAML output goes to STDOUT.
snapshot
command attributes
Attributes | Definition | Requirement |
---|---|---|
--snapshotFormat
|
Creates a JSON or YAML file that represents the current state of the database. | Optional |
Using the snapshot
in the diff
and diffChangeLog
commands
You can use the JSON format snapshot file in the diff
and diffChangeLog
commands. One of the typical workflows is the following:
- Make sure your local environment is up-to-date by getting the latest changelog from source control.
- Configure your
liquibase.properties
file to point to a local development database and run theupdate
command to ensure your target database matches the changelog file. - Take a snapshot of the local development database by running the
snapshot
command:
liquibase --outputFile=myschemaSnapshot.json snapshot --snapshotFormat=json
- Manually change the local development database if needed.
- Append changes to the changelog by running the
diffChangeLog
command:
liquibase --referenceUrl=jdbc:oracle:thin://localhost:9090/mem:test --url=offline:mysql?snapshot=mySnapshot.json diffChangeLog
Note: If you want to see changes without appending them to the changelog file, add --changeLogFile=mydiffchangelog.xml
to the diffChangeLog
command:
liquibase --referenceUrl=jdbc:oracle:thin://localhost:9090/mem:test --url=offline:mysql?snapshot=mySnapshot.json --changeLogFile=mydiffchangelog.xml diffChangeLog
Note: The format for the URL is the following: offline:<db_type>?snapshot=<path/to/snapshot.json>
. Use the name of your database type from the list of the supported databases in place of <db_type>
and the path relative to where the command is running in place of <path/to/snapshot.json>
. If you are using another database, like H2, you may need to wrap your URL in "
: "offline:<db_type>?snapshot=<path/to/snapshot.json>"
.
- Review the changelog file to ensure that it matches your expectations of the manual changes that were made.
- Mark the manual changes as deployed in the local development database by running the changelogSync command:
liquibase changeLogSync
- Commit the changes to the source control.

When running the snapshot
command with the --snapshotFormat
attribute, the output can be as follows:
Liquibase Pro 3.8.7 by Datical licensed to Liquibase Pro Customer until Tue Sep 22 19:00:00 CDT 2020
Liquibase command 'snapshot' was executed successfully.
When running the snapshot
command without indicating the --snapshotFormat
, you receive the following output:
Liquibase Pro 3.8.7 by Datical licensed to Liquibase Pro Customer until Tue Sep 22 19:00:00 CDT 2020
Database snapshot for jdbc:oracle:thin:@localhost:1521:ORCL
-----------------------------------------------------------------
Database type: Oracle
Database version: Oracle Database 11g Release 11.1.0.0.0 - Production
Database user: SCHEMA1
Included types:
com.datical.liquibase.ext.appdba.synonym.Synonym
com.datical.liquibase.ext.storedlogic.checkconstraint.CheckConstraint
com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackage
com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackageBody
com.datical.liquibase.ext.storedlogic.function.Function
com.datical.liquibase.ext.storedlogic.trigger.Trigger
liquibase.structure.core.Catalog
liquibase.structure.core.Column
liquibase.structure.core.ForeignKey
liquibase.structure.core.Index
liquibase.structure.core.PrimaryKey
liquibase.structure.core.Schema
liquibase.structure.core.Sequence
liquibase.structure.core.StoredProcedure
liquibase.structure.core.Table
liquibase.structure.core.UniqueConstraint
liquibase.structure.core.View
Catalog: SCHEMA1
com.datical.liquibase.ext.storedlogic.function.Function:
FUNCTION1
body: CREATE OR REPLACE FUNCTION FUNCTION1 RETURN VARCHAR2 AS
BEGIN
RETURN NULL;
END FUNCTION1;
valid: true
liquibase.structure.core.Index:
PK_DATABASECHANGELOGLOCK
columns:
ID
table: DATABASECHANGELOGLOCK
unique: true
PK_DEPARTMENT
columns:
ID
table: DEPARTMENT
unique: true
PK_DEPARTMENT11
columns:
ID
table: DEPARTMENT11
unique: true
PK_SERVICETECH22
columns:
ID
table: LIBRARY2
unique: true
PK_SERVICETECH222
columns:
ID
table: LIBRARY22
unique: true
PK_SERVICETECH
columns:
ID
table: SERVICETECH
unique: true
liquibase.structure.core.PrimaryKey:
PK_DATABASECHANGELOGLOCK
backingIndex: PK_DATABASECHANGELOGLOCK
columns:
ID
table: DATABASECHANGELOGLOCK
validate: true
PK_DEPARTMENT
backingIndex: PK_DEPARTMENT
columns:
ID
table: DEPARTMENT
validate: true
PK_DEPARTMENT11
backingIndex: PK_DEPARTMENT11
columns:
ID
table: DEPARTMENT11
validate: true
PK_SERVICETECH22
backingIndex: PK_SERVICETECH22
columns:
ID
table: LIBRARY2
validate: true
PK_SERVICETECH222
backingIndex: PK_SERVICETECH222
columns:
ID
table: LIBRARY22
validate: true
PK_SERVICETECH
backingIndex: PK_SERVICETECH
columns:
ID
table: SERVICETECH
validate: true
liquibase.structure.core.StoredProcedure:
PROCEDURE1
body: CREATE OR REPLACE PROCEDURE PROCEDURE1 AS
BEGIN
NULL;
END PROCEDURE1;
valid: true
liquibase.structure.core.Table:
DATABASECHANGELOG
columns:
AUTHOR
nullable: false
order: 2
type: VARCHAR(255 BYTE)
COMMENTS
nullable: true
order: 9
type: VARCHAR(255 BYTE)
CONTEXTS
nullable: true
order: 12
type: VARCHAR(255 BYTE)
DATEEXECUTED
nullable: false
order: 4
type: TIMESTAMP(6)(11)
DEPLOYMENT_ID
nullable: true
order: 14
type: VARCHAR(10 BYTE)
DESCRIPTION
nullable: true
order: 8
type: VARCHAR(255 BYTE)
EXECTYPE
nullable: false
order: 6
type: VARCHAR(10 BYTE)
FILENAME
nullable: false
order: 3
type: VARCHAR(255 BYTE)
ID
nullable: false
order: 1
type: VARCHAR(255 BYTE)
LABELS
nullable: true
order: 13
type: VARCHAR(255 BYTE)
LIQUIBASE
nullable: true
order: 11
type: VARCHAR(20 BYTE)
MD5SUM
nullable: true
order: 7
type: VARCHAR(35 BYTE)
ORDEREXECUTED
nullable: false
order: 5
type: NUMBER(*, 0)
TAG
nullable: true
order: 10
type: VARCHAR(255 BYTE)
DATABASECHANGELOGLOCK
columns:
ID
nullable: false
order: 1
type: NUMBER(*, 0)
LOCKED
nullable: false
order: 2
type: NUMBER(1, 0)
LOCKEDBY
nullable: true
order: 4
type: VARCHAR(255 BYTE)
LOCKGRANTED
nullable: true
order: 3
type: TIMESTAMP(6)(11)
indexes:
PK_DATABASECHANGELOGLOCK
columns:
ID
unique: true
primaryKey: PK_DATABASECHANGELOGLOCK
backingIndex: PK_DATABASECHANGELOGLOCK
columns:
ID
validate: true
DEPARTMENT
columns:
ACTIVE
defaultValue: 1
nullable: true
order: 3
type: NUMBER(1, 0)
ID
nullable: false
order: 1
type: NUMBER(*, 0)
NAME
nullable: false
order: 2
type: VARCHAR(50 BYTE)
indexes:
PK_DEPARTMENT
columns:
ID
unique: true
primaryKey: PK_DEPARTMENT
backingIndex: PK_DEPARTMENT
columns:
ID
validate: true
DEPARTMENT11
columns:
ACTIVE
defaultValue: 1
nullable: true
order: 3
type: NUMBER(1, 0)
ID
nullable: false
order: 1
type: NUMBER(*, 0)
NAME
nullable: false
order: 2
type: VARCHAR(50 BYTE)
indexes:
PK_DEPARTMENT11
columns:
ID
unique: true
primaryKey: PK_DEPARTMENT11
backingIndex: PK_DEPARTMENT11
columns:
ID
validate: true
LIBRARY2
columns:
ACTIVE
defaultValue: 1
nullable: true
order: 3
type: NUMBER(1, 0)
ID
nullable: false
order: 1
type: NUMBER(*, 0)
NAME
nullable: false
order: 2
type: VARCHAR(50 BYTE)
indexes:
PK_SERVICETECH22
columns:
ID
unique: true
primaryKey: PK_SERVICETECH22
backingIndex: PK_SERVICETECH22
columns:
ID
validate: true
LIBRARY22
columns:
ACTIVE
defaultValue: 1
nullable: true
order: 3
type: NUMBER(1, 0)
ID
nullable: false
order: 1
type: NUMBER(*, 0)
NAME
nullable: false
order: 2
type: VARCHAR(50 BYTE)
indexes:
PK_SERVICETECH222
columns:
ID
unique: true
primaryKey: PK_SERVICETECH222
backingIndex: PK_SERVICETECH222
columns:
ID
validate: true
SERVICETECH
columns:
ACTIVE
defaultValue: 1
nullable: true
order: 3
type: NUMBER(1, 0)
ID
nullable: false
order: 1
type: NUMBER(*, 0)
NAME
nullable: false
order: 2
type: VARCHAR(50 BYTE)
indexes:
PK_SERVICETECH
columns:
ID
unique: true
primaryKey: PK_SERVICETECH
backingIndex: PK_SERVICETECH
columns:
ID
validate: true
The snapshot
command produces a JSON file that contains all your objects and places the file in the same directory as your changelog.

{
"snapshot": {
"created": "2019-10-23T16:10:40.306",
"database": {
"productVersion": "Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production\nWith the Partitioning option",
"shortName": "oracle",
"majorVersion": "11",
"minorVersion": "2",
"user": "MYSCHEMA",
"productName": "Oracle",
"url": "jdbc:oracle:thin:@localhost:1521:ORCL"
},
"objects": {
"com.datical.liquibase.ext.appdba.synonym.Synonym": [
{
"synonym": {
"name": "PRIVATETABLESYN",
"objectName": "PRIMARY_TABLE",
"objectSchema": "liquibase.structure.core.Schema#b689101",
"private": true,
"schema": "liquibase.structure.core.Schema#b689101",
"snapshotId": "b689152"
}
}
],
"liquibase.structure.core.Catalog": [
{
"catalog": {
"default": true,
"name": "MYSCHEMA",
"snapshotId": "b689100"
}
}
],
"liquibase.structure.core.Column": [
{
"column": {
"defaultValue": "1!{java.math.BigDecimal}",
"name": "ACTIVE",
"nullable": true,
"order": "3!{java.lang.Integer}",
"relation": "liquibase.structure.core.Table#b689129",
"snapshotId": "b689133",
"type": {
"columnSize": "1!{java.lang.Integer}",
"dataTypeId": "3!{java.lang.Integer}",
"decimalDigits": "0!{java.lang.Integer}",
"typeName": "NUMBER"
}
}
}
],
"liquibase.structure.core.Index": [
{
"index": {
"columns": [
"liquibase.structure.core.Column#b689137"
],
"name": "PK_DATABASECHANGELOGLOCK",
"snapshotId": "b689136",
"table": "liquibase.structure.core.Table#b689135",
"unique": true
}
}
],
"liquibase.structure.core.PrimaryKey": [
{
"primaryKey": {
"backingIndex": "liquibase.structure.core.Index#b689136",
"columns": [
"liquibase.structure.core.Column#b689137"
],
"name": "PK_DATABASECHANGELOGLOCK",
"snapshotId": "b689141",
"table": "liquibase.structure.core.Table#b689135",
"validate": true
}
}
],
"liquibase.structure.core.Schema": [
{
"schema": {
"catalog": "liquibase.structure.core.Catalog#b689100",
"default": true,
"name": "MYSCHEMA",
"snapshotId": "b689101"
}
}
],
"liquibase.structure.core.Table": [
{
"table": {
"columns": [
"liquibase.structure.core.Column#b689109",
"liquibase.structure.core.Column#b689110",
"liquibase.structure.core.Column#b689111",
"liquibase.structure.core.Column#b689112",
"liquibase.structure.core.Column#b689113",
"liquibase.structure.core.Column#b689114",
"liquibase.structure.core.Column#b689115",
"liquibase.structure.core.Column#b689116",
"liquibase.structure.core.Column#b689117",
"liquibase.structure.core.Column#b689118",
"liquibase.structure.core.Column#b689119",
"liquibase.structure.core.Column#b689120",
"liquibase.structure.core.Column#b689121",
"liquibase.structure.core.Column#b689122"
],
"name": "DATABASECHANGELOG",
"schema": "liquibase.structure.core.Schema#b689101",
"snapshotId": "b689108"
}
}
],
"liquibase.structure.core.View": [
{
"view": {
"columns": [
"liquibase.structure.core.Column#b689149",
"liquibase.structure.core.Column#b689150",
"liquibase.structure.core.Column#b689151"
],
"definition": "SELECT \"ID\",\"NAME\",\"ACTIVE\"\n \nFROM \"MYSCHEMA\".\"DEPARTMENT\"",
"editioning": false,
"name": "VIEW1",
"schema": "liquibase.structure.core.Schema#b689101",
"snapshotId": "b689148"
}
}
],
"snapshotControl": {
"snapshotControl": {
"includedType": [
"com.datical.liquibase.ext.appdba.synonym.Synonym",
"com.datical.liquibase.ext.storedlogic.checkconstraint.CheckConstraint",
"com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackage",
"com.datical.liquibase.ext.storedlogic.databasepackage.DatabasePackageBody",
"com.datical.liquibase.ext.storedlogic.function.Function",
"com.datical.liquibase.ext.storedlogic.javalogic.JavaClass",
"com.datical.liquibase.ext.storedlogic.javalogic.JavaSource",
"com.datical.liquibase.ext.storedlogic.trigger.Trigger",
"liquibase.structure.core.Catalog",
"liquibase.structure.core.Column",
"liquibase.structure.core.ForeignKey",
"liquibase.structure.core.Index",
"liquibase.structure.core.PrimaryKey",
"liquibase.structure.core.Schema",
"liquibase.structure.core.Sequence",
"liquibase.structure.core.StoredProcedure",
"liquibase.structure.core.Table",
"liquibase.structure.core.UniqueConstraint",
"liquibase.structure.core.View"
]
}
}
}
}
}
Liquibase Community snapshot
categories:
- Catalog
- Column
- Foreign Key
- Index
- Primary Key
- Schema
- Sequence
- Unique Constraints
- View
Liquibase Pro snapshot
categories:
- Package
- Package Body
- Procedures
- Function
- Trigger
- Synonyms
- Check Constraints