-
Notifications
You must be signed in to change notification settings - Fork 0
/
typo3dump
executable file
·89 lines (75 loc) · 4.97 KB
/
typo3dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Check first argument (the TYPO3 DocumentRoot to dump)
if [ -z "$1" ]; then
echo "Usage: typo3dump.sh /var/www/example.com/";
exit
fi
TAR_NAME=/root/$(/usr/bin/basename "$1").tar
DOCUMENT_ROOT=$(/usr/bin/dirname "$1")
TYPO3_DIR_NAME=$(/usr/bin/basename "$1")
TYPO3_CONF_DIR=$(readlink -e "${1}typo3conf" || readlink -e "${1}public/typo3conf")
# Check for typo3conf directory
if [ ! -d "$TYPO3_CONF_DIR" ]; then
echo "This is not a typo3 instance"
exit
fi
# Set and check the LocalConfiguration.php file
CONFIG=$(readlink -e $TYPO3_CONF_DIR/{LocalConfiguration,localconf}.php | head -1)
if [ -z "$CONFIG" ]; then
echo "Couldn't find neither LocalConfiguration.php nor localconf.php"
exit
fi
# Get the database name
DATABASE=$(/usr/bin/php -r "\$config=include(\"$CONFIG\"); \
if (isset (\$config['DB']['database'])) { \
echo \$config['DB']['database']; \
} elseif (isset (\$config['DB']['Connections']['Default']['dbname'])) { \
echo \$config['DB']['Connections']['Default']['dbname']; \
} elseif (isset (\$typo_db)) { \
echo \$typo_db; \
} else { \
echo \"Couldn't find the DB name in $CONFIG\"; \
} \
")
# Get the database user
DB_USER=$(/usr/bin/php -r "\$config=include(\"$CONFIG\"); \
if (isset (\$config['DB']['username'])) { \
echo \$config['DB']['username']; \
} elseif (isset (\$config['DB']['Connections']['Default']['user'])) { \
echo \$config['DB']['Connections']['Default']['user']; \
} elseif (isset (\$typo_db_username)) { \
echo \$typo_db_username; \
} else { \
echo \"Couldn't find the DB name in $CONFIG\"; \
} \
")
# Check for empty database name and check if database exists in mysql
[[ "$DATABASE" =~ "Couldn't" ]] && { echo "$DATABASE"; exit; }
[[ $(mysql --defaults-file=/etc/mysql/debian.cnf -e "show databases like '$DATABASE';") ]] || { echo "Couldn't find database: $DATABASE"; exit; }
# Tables to exclude
EXCLUDES=('cache_pages' 'cache_extensions' 'cache_hash' 'link_cache' 'cache_typo3temp_log' 'cache_imagesizes' 'cache_md5params' 'cache_pages' 'cache_pagesection' 'cache_treelist' 'cachingframework_cache_hash'
'cachingframework_cache_hash_tags' 'cachingframework_cache_pages' 'cachingframework_cache_pages_tags' 'cachingframework_cache_pagesection' 'cachingframework_cache_pagesection_tags'
'be_sessions' 'fe_session_data' 'fe_sessions' 'index_fulltext' 'index_grlist' 'index_phash' 'index_rel' 'index_section' 'index_stat_search' 'index_stat_word' 'index_words' 'index_debug'
'cf_cache_hash' 'cf_cache_hash_tags' 'cf_cache_news_category' 'cf_cache_news_category_tags' 'cf_cache_pages' 'cf_cache_pagesection' 'cf_cache_pagesection_tags' 'cf_cache_pages_tags' 'cf_cache_rootline'
'cf_cache_rootline_tags' 'cf_extbase_datamapfactory_datamap' 'cf_extbase_datamapfactory_datamap_tags' 'cf_extbase_object' 'cf_extbase_object_tags' 'cf_extbase_reflection' 'cf_extbase_reflection_tags'
'cf_extbase_typo3dbbackend_queries' 'cf_extbase_typo3dbbackend_queries_tags' 'cf_extbase_typo3dbbackend_tablecolumns' 'cf_extbase_typo3dbbackend_tablecolumns_tags' 'cf_fluidcontent' 'cf_fluidcontent_tags'
'cf_flux' 'cf_flux_tags' 'cf_vhs_main' 'cf_vhs_main_tags' 'cf_vhs_markdown' 'cf_vhs_markdown_tags' 'link_cache' 'link_oldlinks' 'tt_news_cache' 'sys_history' 'sys_log' 'sys_dmail_maillog')
# Ignore cache tables from the list
for TABLE in ${EXCLUDES[*]}; do
IGNORES+=" --ignore-table $1.$TABLE"
done
# Export db struct
/usr/bin/mysqldump --defaults-file=/etc/mysql/debian.cnf --routines $DATABASE -d > "$1$DATABASE.sql"
# Export data without ignored tables
/usr/bin/mysqldump --defaults-file=/etc/mysql/debian.cnf $DATABASE -nt $IGNORES >> "$1$DATABASE.sql"
# Make the tar ball
/bin/tar cvfp $TAR_NAME -C $DOCUMENT_ROOT $TYPO3_DIR_NAME --exclude typo3temp --exclude */_processed_ --exclude typo3conf/*.log --exclude typo3conf/temp_*
# Gzip tar ball
/bin/gzip -f $TAR_NAME
echo "All user for database $DATABASE:"
mysql --defaults-file=/etc/mysql/debian.cnf -e "select user,host,db from mysql.db where db='$DATABASE';"
echo "All grants for user $DB_USER:"
mysql --defaults-file=/etc/mysql/debian.cnf -e "show grants for '$DB_USER'@'localhost';"
echo "You may want to drop the database user and database"
echo "DROP USER '$DB_USER'@'localhost';"
echo "DROP DATABASE $DATABASE;"