|
| 1 | +#!/bin/bash |
| 2 | +# info: Dumps the files of a site into a zip archive |
| 3 | +# options: USER DOMAIN [TYPE] |
| 4 | +# |
| 5 | +# example: v-dump-site user domain |
| 6 | +# example: v-dump-site user domain full |
| 7 | +# |
| 8 | +# Dumps site files in /backup/user.domain.timestamp.zip |
| 9 | + |
| 10 | +#----------------------------------------------------------# |
| 11 | +# Variables & Functions # |
| 12 | +#----------------------------------------------------------# |
| 13 | + |
| 14 | +# Argument definition |
| 15 | +user=$1 |
| 16 | +domain=$2 |
| 17 | +type=$3 |
| 18 | + |
| 19 | +# Includes |
| 20 | +# shellcheck source=/etc/hestiacp/hestia.conf |
| 21 | +source /etc/hestiacp/hestia.conf |
| 22 | +# shellcheck source=/usr/local/hestia/func/main.sh |
| 23 | +source $HESTIA/func/main.sh |
| 24 | +# load config file |
| 25 | +source_conf "$HESTIA/conf/hestia.conf" |
| 26 | + |
| 27 | +check_args '2' "$#" 'USER DOMAIN' |
| 28 | +is_format_valid 'user' 'domain' |
| 29 | +is_object_valid 'user' 'USER' "$user" |
| 30 | +is_object_unsuspended 'user' 'USER' "$user" |
| 31 | +is_object_valid 'web' 'DOMAIN' "$domain" |
| 32 | + |
| 33 | +# Perform verification if read-only mode is enabled |
| 34 | +check_hestia_demo_mode |
| 35 | + |
| 36 | +#----------------------------------------------------------# |
| 37 | +# Action # |
| 38 | +#----------------------------------------------------------# |
| 39 | + |
| 40 | +# Create timestamp in Y-M-D_h-m-s format |
| 41 | +timestamp=$(date +'%G-%m-%d_%H-%M-%S') |
| 42 | + |
| 43 | +# echo filename for use in the php |
| 44 | +echo "$user.$domain.$timestamp.zip" |
| 45 | + |
| 46 | +if [ "$type" = "full" ]; then |
| 47 | + cd /home/$user/web/$domain/ |
| 48 | +else |
| 49 | + cd /home/$user/web/$domain/public_html/ |
| 50 | +fi |
| 51 | + |
| 52 | +zip -rq $BACKUP/$user.$domain.$timestamp.zip . |
| 53 | + |
| 54 | +if [[ -f "$BACKUP/$user.$domain.$timestamp.zip" ]]; then |
| 55 | + echo "$BACKUP/$user.$domain.$timestamp.zip" |
| 56 | + echo "rm $BACKUP/$user.$domain.$timestamp.zip" | at now + 1 hour |
| 57 | +fi |
| 58 | + |
| 59 | +#----------------------------------------------------------# |
| 60 | +# Hestia # |
| 61 | +#----------------------------------------------------------# |
| 62 | + |
| 63 | +# Logging |
| 64 | +log_event "$OK" "$ARGUMENTS" |
| 65 | + |
| 66 | +exit |
| 67 | + |
0 commit comments