Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

CreateBackupSh

Oliver Salzburg edited this page Jul 14, 2014 · 12 revisions

Introduction

The main purpose of createBackup.sh is to create a snapshot of all files in the TYPO3 installation as well as the TYPO3 database. To restore such a snapshot use restoreBackup.sh.

Arguments

$ ./createBackup.sh --help
  Usage: ./createBackup.sh [OPTIONS]

  Core:
  --help              Display this help and exit.
  --verbose           Display more detailed messages.
  --quiet             Do not display anything.
  --force             Perform actions that would otherwise abort the script.
  --update            Tries to update the script to the latest version.
  --update-check      Checks if a newer version of the script is available.
  --export-config     Prints the default configuration of this script.
  --extract-config    Extracts configuration parameters from TYPO3.
  --base=PATH         The name of the base path where TYPO3 is
                      installed. If no base is supplied, "typo3" is used.

  Options:
  --skip-db           Skips dumping the database before creating the archive.
  --skip-fs           Skips archiving the TYPO3 directory.
  --exclude=pattern   Will exclude files that match the pattern from the
                      backup.
  --no-data=pattern   For MySQL tables that match the pattern, only the table
                      structure will be exported.

  Database:
  --hostname=HOST     The name of the host where the TYPO3 database is running.
  --username=USER     The user name to use when connecting to the TYPO3
                      database.
  --password=PASSWORD The password to use when connecting to the TYPO3
                      database.
  --database=DB       The name of the database in which TYPO3 is stored.

Overview

For general information regarding the configuration of scripts in the typo3scripts suite, please see the article about Configuration.

Hint: It may be desirable to share a configuration file (at least) between createBackup.sh and restoreBackup.sh.

Command Line Parameters

  • --help

    Prints the output seen above, giving an overview of available command line parameters.

  • --verbose

    Enable verbose (more detailed) output.

  • --quiet

    Reduced verbosity (less detailed) output.

  • --force

    Perform actions that would otherwise stop execution.

  • --update

    Invokes the self-updating mechanism in this script. This will download the latest release version from the official source code repository and replace your current script.

    Note: To perform a quick check if a new version is available, run createBackup.sh with the --update-check parameter. If a new version is found online, the following message will be printed to the standard output:

    NOTE: New version available!
    

    In previous versions, this check would be performed every time you run the script.

  • --export-config

    Print the default configuration of the script to the standard output.

    This allows for easy generation of a default config file, like so:

      $ ./createBackup.sh --export-config > typo3scripts.conf
    
  • --extract-config

    Tries to read the database-related parameters out of the TYPO3 configuration file.

    This allows for easy generation of a base config file for other typo3scripts after you have completed your TYPO3 installation.

      $ ./createBackup.sh --extract-config > typo3scripts.conf
    

    In case you're using a non-default TYPO3 installation directory, make sure to supply the --base parameter before the --extract-config parameter.

      $ ./createBackup.sh --base=myt3site --extract-config > typo3scripts.conf
    

    Note: This functionality is currently not compatible with TYPO3 6.0 configuration file format.

  • --base / BASE

    By default, it is assumed that the TYPO3 installation is located in a sub-folder relative to the current working directory, named typo3. Use --base if the installation is placed in a differently named sub-folder.

      $ ./createBackup.sh --base=myt3site
    
  • --skip-db / SKIP_DB

    Skips exporting of the database completely. Useful when you only want to package up the file system.

  • --skip-fs / SKIP_FS

    Skips archiving any files. Useful when you only want to export the database.

  • --exclude / EXCLUDE

    Allows you to define a pattern for files that should not be included in the archive. The pattern will be passed directly to tar with the TYPO3 BASE path of your installation prepended. The parameter can be used multiple times to exclude multiple patterns.

      $ ./createBackup.sh --exclude=typo3temp/* --exclude=typo3conf/deprecation_*.log
    

    Please note that a pattern like --exclude=typo3temp/* would ignore all files within the folder, but put the folder itself into the archive. This is in contrast to specifying --exclude=typo3temp, which would omit the whole folder from the archive. If the folder is not contained within the archive it will also not be re-created when restoring the archive later on.

    Also note that the configuration variable EXCLUDE in an array and needs to be defined like:

      EXCLUDE[0]='typo3temp/*'
      EXCLUDE[1]='typo3conf/deprecation_*.log'
    

    or

      EXCLUDE=('typo3temp/*' 'typo3conf/deprecation_*.log')
    

    For compatibility reasons, EXCLUDE should not be defined in the core configuration file typo3scripts.conf, but only in the script-specific createBackup.conf!

  • --no-data / NO_DATA

    Allows you to define a pattern for MySQL tables that should not have their contained data exported to the database dump. The pattern is internally processed and matched against all tables in the target database. The parameter can be used multiple times.

      $ ./createBackup.sh --no-data=index_* --no-data=cache_*
    

    The table structure will still be exported to the database dump to allows for seamless restoration on the target.

    Also note that the configuration variable NO_DATA in an array and needs to be defined like:

      NO_DATA[0]='index_*'
      NO_DATA[1]='cache_*'
    

    or

      NO_DATA=('index_*' 'cache_*')
    

    For compatibility reasons, NO_DATA should not be defined in the core configuration file typo3scripts.conf, but only in the script-specific createBackup.conf!

  • --hostname / HOST

    The name of the host where the database for TYPO3 is running.

  • --username / USER

    The user name for the connection to the database for the TYPO3 installation.

  • --password / PASS

    The password for the connection to the database for the TYPO3 installation.

  • --database / DB

    The name of the database for the TYPO3 installation.

Examples

Installation

/var/www$ cd t3site/
/var/www/t3site$ wget https://raw.github.com/oliversalzburg/typo3scripts/master/createBackup.sh
/var/www/t3site$ chmod 700 createBackup.sh

Creating a snapshot

/var/www/t3site$ sudo ./createBackup.sh
Checking dependencies...Succeeded.
Creating TYPO3 backup 'typo3-2013-03-14-23-43.tgz'...
Creating database dump at 'typo3/database.sql'...Done
Compressing TYPO3 installation...Done.

Selective snapshot

Here, we're demonstrating how to exclude certain data from a backup. In this case we're opting to leave out much of the temporary data of a TYPO3 installation.

Hint: This can be automated by putting the following into a script-specific configuration file (createBackup.conf):

NO_DATA=("cache_*" "cf_*" "index_*")  
EXCLUDE=("typo3temp/*" "typo3conf/deprecation_*.log" "typo3conf/temp_CACHED_*_ext_localconf.php" "typo3conf/temp_CACHED_FE_*_ext_localconf.php")
$ sudo ./createBackup.sh --exclude=typo3temp/* --exclude=typo3conf/deprecation_*.log --exclude=typo3conf/temp_CACHED_*_ext_localconf.php \
  --exclude=typo3conf/temp_CACHED_FE_*_ext_localconf.php --no-data=index_* --no-data=cf_* --no-data=cache_* --verbose
Checking dependencies...
Checking dependency 'wget' =>/usr/bin/wget
Checking dependency 'curl' =>/usr/bin/curl
Checking dependency 'md5sum' =>/usr/bin/md5sum
Checking dependency 'grep' =>/bin/grep
Checking dependency 'awk' =>/usr/bin/awk
Checking dependency 'tar' =>/bin/tar
Checking dependency 'mysqldump' =>/usr/bin/mysqldump
Succeeded.
Creating TYPO3 backup 'typo3-2013-03-14-22-31.tgz'...
Creating database dump at 'typo3/database.sql'...
Excluding 'demo.cache_extensions'
Excluding 'demo.cache_imagesizes'
Excluding 'demo.cache_md5params'
Excluding 'demo.cache_sys_dmail_stat'
Excluding 'demo.cache_treelist'
Excluding 'demo.cache_typo3temp_log'
Excluding 'demo.cf_cache_hash'
Excluding 'demo.cf_cache_hash_tags'
Excluding 'demo.cf_cache_pages'
Excluding 'demo.cf_cache_pages_tags'
Excluding 'demo.cf_cache_pagesection'
Excluding 'demo.cf_cache_pagesection_tags'
Excluding 'demo.cf_extbase_object'
Excluding 'demo.cf_extbase_object_tags'
Excluding 'demo.cf_extbase_reflection'
Excluding 'demo.cf_extbase_reflection_tags'
Excluding 'demo.cf_news_categorycache'
Excluding 'demo.cf_news_categorycache_tags'
Excluding 'demo.cf_workspaces_cache'
Excluding 'demo.cf_workspaces_cache_tags'
Excluding 'demo.index_config'
Excluding 'demo.index_debug'
Excluding 'demo.index_fulltext'
Excluding 'demo.index_grlist'
Excluding 'demo.index_phash'
Excluding 'demo.index_rel'
Excluding 'demo.index_section'
Excluding 'demo.index_stat_search'
Excluding 'demo.index_stat_word'
Excluding 'demo.index_words'
Done
Exporting structure for previously ignored tables...Done
Excluding 'typo3/typo3temp/*'
Excluding 'typo3/typo3conf/deprecation_*.log'
Excluding 'typo3/typo3conf/temp_CACHED_*_ext_localconf.php'
Excluding 'typo3/typo3conf/temp_CACHED_FE_*_ext_localconf.php'
Compressing TYPO3 installation...Done.
Deleting database dump...Done!

This example assumes that you previously created a configuration file typo3scripts.conf to share between scripts. Please see the article about Configuration for more information.