Skip to content

Commit 210d757

Browse files
author
Martin Szymanski
committed
Merge branch 'release/0.6.1'
2 parents db7a4e2 + 94b6ee4 commit 210d757

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ DEPLOY_ASSETS_DIR="uploads"
99

1010
# Restart PHP if symlinks are cached – optional
1111
DEPLOY_RESTART_PHP=""
12+
13+
# Backups to keep
14+
DEPLOY_KEEP_BACKUPS=5

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Things change, people change, everything changes.
44

5+
## [0.6.1](https://github.com/elfacht/craft-deploy/compare/0.6.0...0.6.1) - 2019-07-15
6+
### Added
7+
- Added `DEPLOY_KEEP_BACKUPS` option and function.
8+
59
## [0.6.0](https://github.com/elfacht/craft-deploy/compare/0.5.0...0.6.0) - 2019-07-08
610
### Added
711
- Added `.env` environment to separate config from code.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Creates the necessary `releases`, `shared` and `shared/web` folders on the serve
4545
- Runs `./craft migrate/all` and `./craft project-config/sync`.
4646
- Creates a symlink from the `current` folder to the newest release.
4747
- Deletes old releases and keeps max. 5 releases.
48+
- Deletes oldest backup and keeps max. `[DEPLOY_KEEP_BACKUPS]` backups.
4849
- Restarts PHP to delete symlink cache (optional)
4950

5051
### gitlab-webhook-push.php

deploy.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ GIT_REPO=$(read_var DEPLOY_REPO .env)
3535
ROOT_PATH=$(read_var DEPLOY_ROOT .env)
3636
ASSETS_DIR=$(read_var DEPLOY_ASSETS_DIR .env)
3737
RESTART_PHP=$(read_var DEPLOY_RESTART_PHP .env)
38+
KEEP_BACKUPS=$(read_var DEPLOY_KEEP_BACKUPS .env)
3839

3940
#######################################
4041
# Exit if any command fails
@@ -158,6 +159,29 @@ if composer install --no-interaction --prefer-dist --optimize-autoloader; then
158159
printf -- ' DONE!\n';
159160
fi
160161

162+
#######################################
163+
# Kepp max. X backups,
164+
# delete oldest backup
165+
#######################################
166+
COUNT=`/bin/ls -l $ROOT_PATH/shared/storage/backups | /usr/bin/wc -l`
167+
MINBACKUPS=$KEEP_BACKUPS+1 # Keep X releases
168+
169+
if [[ $COUNT -gt $MINBACKUPS ]]; then
170+
OLDEST_BACKUP=$(ls -tr $ROOT_PATH/shared/storage/backups/* | head -1)
171+
printf -- "- Delete oldest backup '$OLDEST_BACKUP' .."
172+
173+
DONE=0;
174+
while [ $DONE -eq 0 ]; do
175+
rm -rf $OLDEST_BACKUP
176+
177+
if [ "$?" = "0" ]; then DONE=1; fi;
178+
printf -- '.';
179+
sleep 1;
180+
done
181+
182+
printf -- ' DONE!\n';
183+
fi
184+
161185
#######################################
162186
# Restart PHP
163187
#######################################

0 commit comments

Comments
 (0)