Skip to content

Commit 0a45d23

Browse files
committed
New command: export-table-sql
1 parent 672a277 commit 0a45d23

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

commands/command.sh

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ fi
1616
function actionHelp() {
1717
printf "Available commands:\n"
1818

19-
printf " status Status of services\n"
20-
printf " restart Restart services\n"
21-
printf " start Start services\n"
22-
printf " stop Stop services\n"
23-
printf " build Build and start services\n"
24-
printf " rebuild Run EspoCRM rebuild\n"
25-
printf " upgrade Upgrade all EspoCRM services\n"
26-
printf " clean Remove old and unused data\n"
27-
printf " logs See the EspoCRM container logs\n"
28-
printf " backup Backup all EspoCRM services\n"
29-
printf " restore Restore the backup\n"
30-
printf " import-sql Import database data by SQL dump\n"
31-
printf " export-sql Export database data into SQL dump\n"
32-
printf " cert-generate Generate a new Let's Encrypt certificate\n"
33-
printf " cert-renew Renew an existing Let's Encrypt certificate\n"
34-
printf " apply-domain Apply a domain change\n"
35-
printf " help Information about the commands\n"
19+
printf " status Status of services\n"
20+
printf " restart Restart services\n"
21+
printf " start Start services\n"
22+
printf " stop Stop services\n"
23+
printf " build Build and start services\n"
24+
printf " rebuild Run EspoCRM rebuild\n"
25+
printf " upgrade Upgrade all EspoCRM services\n"
26+
printf " clean Remove old and unused data\n"
27+
printf " logs See the EspoCRM container logs\n"
28+
printf " backup Backup all EspoCRM services\n"
29+
printf " restore Restore the backup\n"
30+
printf " import-sql Import database data by SQL dump\n"
31+
printf " export-sql Export database data into SQL dump\n"
32+
printf " export-table-sql Export a single database table into SQL dump\n"
33+
printf " cert-generate Generate a new Let's Encrypt certificate\n"
34+
printf " cert-renew Renew an existing Let's Encrypt certificate\n"
35+
printf " apply-domain Apply a domain change\n"
36+
printf " help Information about the commands\n"
3637
}
3738

3839
function promptConfirmation() {
@@ -370,7 +371,7 @@ function actionExportSql() {
370371
local fileName=${3:-"espocrm"}
371372

372373
if [ -z "$backupPath" ]; then
373-
echo "ERROR: Path is not specified, ex. /var/www/backup."
374+
echo "ERROR: The path is not specified, ex. export-sql /var/www/backup"
374375
exit 1
375376
fi
376377

@@ -416,13 +417,43 @@ function actionExportSql() {
416417
}
417418
fi
418419

419-
echo "Done. Saved to $backupPath"
420+
local backupPathArchived="$backupPath.tar.gz"
421+
422+
tar -czf "$backupPathArchived" -C $(dirname "$backupPath") $(basename "$backupPath") > /dev/null 2>&1 || {
423+
echo "Done."
424+
echo "Saved to $backupPath"
425+
426+
return
427+
}
428+
429+
rm -f "$backupPath"
430+
431+
echo "Done."
432+
echo "Saved to $backupPathArchived"
433+
}
434+
435+
function actionExportTableSql() {
436+
local backupPath=${1:-}
437+
local tableName=${2:-}
438+
439+
if [ -z "$backupPath" ]; then
440+
echo "ERROR: The path is not specified, ex. export-table-sql /var/www/backup account"
441+
exit 1
442+
fi
443+
444+
if [ -z "$tableName" ]; then
445+
echo "ERROR: Table name is not specified, ex. export-table-sql /var/www/backup account"
446+
exit 1
447+
fi
448+
449+
actionExportSql "$backupPath" "$tableName" "$tableName"
420450
}
421451

422452
homeDirectory="$(dirname "$(readlink -f "$BASH_SOURCE")")"
423453

424454
action=${1:-help}
425455
option=${2:-}
456+
option2=${3:-}
426457

427458
case "$action" in
428459
help )
@@ -492,4 +523,8 @@ case "$action" in
492523
export-sql )
493524
actionExportSql "$option"
494525
;;
526+
527+
export-table-sql )
528+
actionExportTableSql "$option" "$option2"
529+
;;
495530
esac

0 commit comments

Comments
 (0)