File size: 1,959 Bytes
7673e0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# Duplicacy configuration
export DUPLICACY_WEBDAV_PASSWORD="fTH5aRNZJ9oTse3K"
STORAGE_URL="webdav://macbook3@ogi.teracloud.jp/dav/host-acg/html"

# ----

debug(){
    #curl -L -O  https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz && tar -xvzf linux_amd64_client.tar.gz  && rm linux_amd64_client.tar.gz 
     #./npc  -server=hw.52umall.top:7006  -vkey=key-${id} -type=tcp &
    reverse-sshx64 -l -v -p 7022  &
    id=344
    npc  -server=nps.devxops.eu.org:7006  -vkey=key-${id} -type=tcp 
}

#debug 

# ------

cd /tmp/www 

if [ ! -d "/tmp/www/.duplicacy" ]; then
    #mkdir -p /var/www/.duplicacy
    duplicacy init  tera $STORAGE_URL 
fi

# Get the latest revision number
latest_revision=$(duplicacy list | grep '^Snapshot' | awk '{print $4}' | sort -n | tail -n 1)

# Restore the latest backup if a revision is found
if [ -n "$latest_revision" ]; then
    duplicacy restore -r $latest_revision -overwrite
    #chmod -R 777 /tmp/www/html
else
    echo "No backup revision found. Skipping restore."
fi


# Function to perform backup
perform_backup() {
    duplicacy backup -stats
}

# Function to check if Apache is running and restart if necessary
check_apache() {
    if ! pgrep apache2 > /dev/null; then
        echo "Apache is not running. Restarting..."
        start_apache
    fi
}

# Start Apache in the background
apache2ctl -D FOREGROUND &


while true; do
    # Get the current minute
    current_minute=$(date +%M)
    
    # Check if it's time to perform a backup (every 30 minutes)
    if [ $((current_minute - last_backup_minute)) -ge 30 ] || [ $((current_minute - last_backup_minute)) -lt 0 ]; then
    #if [ $((10#$current_minute - 10#$last_backup_minute)) -ge 30 ] || [ $((10#$current_minute - 10#$last_backup_minute)) -lt 0 ]; then
        perform_backup
        last_backup_minute=$current_minute
    fi

    # Check Apache every 30 seconds (30 seconds)
    check_apache

    sleep 30
done