Sari la conținutul principal
FreeThree checks for your projectUptime, accessibility, SEO and cookie checks for your project
Menu

Database and files

Copy a database with personal data replaced, dump and load databases, keep local checkpoints and move files.

On this page

The CLI moves data between your hosted environments and your computer: the database, and the files in your persistent folders. Copies that leave a server have personal data replaced with made-up values by default. Loading data into a hosted environment is always a deliberate step, and it is checked against your permissions.

Copy the live database to your computer

tilizy db:pull

The command takes a dump of the live database with personal data replaced and loads it into your local website. The live database itself is never changed. Passwords are replaced as well, so on Drupal sign in to the refreshed copy with tilizy drupal:login.

OptionWhat it does
-e <branch>, --stagingCopies from another environment instead of live.
--keepKeeps the downloaded .sql file instead of deleting it.
--post-deployRuns your post_deploy hooks on the copied data afterwards. Use it when your checkout is ahead of the environment you copied from.
--rawCopies the data as it is, with real personal data. This needs a separate permission.

How personal data is replaced

Your project declares which database columns hold personal data, in .tilizy/security.yml. Each column gets a kind, and the kind decides the replacement.

pii:
  users_field_data:
    mail: email
    name: name
    pass: bcrypt
  webform_submission_data:
    value: freetext

The kinds are email, name, phone, address, ip, useragent, url, date, bcrypt, hash, freetext, json and "null", written in quotes. The same original value always becomes the same made-up value, so records that belong together still match across tables. The replacement runs on a temporary copy on the server, before anything is sent.

A column that is not declared is copied as it is. Check the file against the real database to find columns you forgot:

tilizy security:validate --check-schema

Dump a database to a file

The local database, exactly as it is:

tilizy db:dump -o local.sql

A hosted environment, with personal data replaced:

tilizy db:dump --prod -o live.sql

Load a dump

Into your local website:

tilizy db:load live.sql

The command accepts .sql and .sql.gz. After loading, it runs your deploy hooks so that the database matches the code of your checkout.

Into a hosted environment:

tilizy db:load live.sql -e staging
Warning: Loading replaces the database of the target environment.

Loading into a hosted environment follows these rules:

  • A dump with personal data replaced can never be loaded into live. No option overrides this: made-up data must not replace real records.
  • Any other dump needs a permission on the project and an explicit confirmation, and the load is recorded.
  • Loading into a live environment that already holds data needs a second approval. The command prints an approval number. When the approval is given, run the same command again with --resume <number>.
  • The first load into a new, empty live environment needs no second approval.

Checkpoints of your local database

A snapshot is a quick local checkpoint. Take one before you try something destructive, and return to it as often as you like.

tilizy snapshot:create before-migration
tilizy snapshot:list
tilizy snapshot:restore before-migration
tilizy snapshot:delete before-migration

--include-files also captures the persistent folders. tilizy snapshot:restore --latest returns to the most recent snapshot. A restore replaces the current local database and runs your deploy hooks again. Snapshots exist only on your computer and are not committed. For a hosted environment, use backups.

Files

The files commands work on the persistent folders you declared under mounts in the project file. They work on hosted environments only, and on live unless you pass -e <branch> or --staging. The value for --mount is the persistent name of the folder.

CommandWhat it does
tilizy files:pullCopies every persistent folder of live into your local website. Existing local files are overwritten, others stay. --mount limits it to one folder. --clean empties the local folder first.
tilizy files:list --mount filesLists what is in a folder. --path starts lower down, --max-depth sets how deep.
tilizy files:download --mount files -o files.tar.gzDownloads a folder as one archive.
tilizy files:upload ./export --mount filesUploads a folder, a single file or a .tar or .tar.gz archive.
tilizy files:rm --mount files --path old/importDeletes one path. Add --recursive for a folder.

files:upload has three modes, chosen with --mode:

  • merge, the default, adds new files and leaves existing ones alone.
  • overwrite also replaces files that already exist.
  • replace deletes everything in the folder first.

Files your project lists under files.exclude in .tilizy/security.yml never leave the server: downloads skip them.

What can go wrong

  • The command is refused. Copying data out of an environment and loading data into one both need permissions on the project. Being signed in is not enough.
  • Uploaded files land in the wrong place. When you upload a folder, its contents go straight into the top of the persistent folder, not into a subfolder with its name. To keep them together, upload an archive whose entries start with the subfolder you want.
  • The wrong environment. tilizy files:rm without a flag deletes on live. Pass -e <branch> for anything else.
  • Content from your checkout is missing after a pull. The pulled database holds the content of the environment you copied from, and nothing else. If your post_deploy hooks import content from the repository, add --post-deploy to run them on top.

Next: Backups and restore and Run your website locally.