Pimcoreバックアップ(履歴データのクリア)

バックアップを実行する前に、

Cleanup Data Storage

ドキュメント、オブジェクト、アセットのバージョンクリーンアップ

# ./bin/console pimcore:maintenance -f -j versioncleanup

Clear Cache

キャッシュクリア(–env=prod or --env=dev)

# bin/console cache:clear --env=prod

1. asset、object、documentの履歴データをクリア

2. Admin画面のTools > Recycle Binの中身を削除すること


1.asset、object、documentの履歴データをクリア
100-200MBの容量が削除されます。

// replace ### with the name of your database
// you can also use “object” or “document” instead of “asset”

mysqlへログイン後、pimcoreデータベースversionsのctype: asset, object, documentを削除します。

$sudo mysql -u user_name -p 
> DELETE FROM database_name.versions WHERE ctype='asset';
$ sudo rm -r var/versions/asset

2.Admin画面のTools > Recycle Binの中身を削除

管理画面でゴミ箱の中身を削除します。500MB程保存されている場合が有ります。

バックアップに不要なフォルダーを除外

https://pimcore.com/docs/5.x/Development_Documentation/Administration_of_Pimcore/Backups.html

$ cd /var/www/pimcore_folder
$ sudo tar cfv website/var/backup/pimcore.tar  --exclude='./exclude_folder' ./
$ sudo mysqldump -u username -p database_name > website/var/backup/pimcore.sql

Tarアーカイブに上記のsqlデータを格納

$ cd website/var/backup
$ sudo tar rf pimcore.tar pimcore.sql

zipによる圧縮ファイル作成

$ sudo gzip pimcore.tar

バックアップ後は移動して削除のこと。

tarコマンド補足

tar+gzipファイル同時生成

$ sudo tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

Here’s what those switches actually mean:

  • -c: C reate an archive.
  • -z: Compress the archive with g z ip.
  • -v: Display progress in the terminal while creating the archive, also known as “ v erbose” mode. The v is always optional in these commands, but it’s helpful.
  • -f: Allows you to specify the f ilename of the archive.

特定フォルダの除外

$ sudo tar -czvf archive.tar.gz /home/ubuntu --exclude=/home/ubuntu/Downloads --exclude=/home/ubuntu/.cache

ファイル形式を指定して除外

$ sudo tar -czvf archive.tar.gz /home/ubuntu --exclude=*.mp4

展開

$ tar -xzvf archive.tar.gz

展開先フォルダを指定

$ sudo tar -xzvf archive.tar.gz -C /tmp

展開オプション

 --strip-components count
         (x mode only) Remove the specified number of leading path ele-
         ments.  Pathnames with fewer elements will be silently skipped.
         Note that the pathname is edited after checking inclusion/exclu-
         sion patterns but before security checks.

tar.gzファイルの3階層下のファイル・フォルダ郡を展開したい時

$ sudo tar -xzvf archive.tar.gz -C /tmp --strip-components 3