mirror of
https://github.com/Sevichecc/pleroma-backup-script.git
synced 2025-04-30 16:59:31 +08:00
Compare commits
No commits in common. "main" and "1.0.1" have entirely different histories.
5 changed files with 67 additions and 73 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
.DS_Store
|
|
28
backup-bot.py
Normal file
28
backup-bot.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
import random
|
||||||
|
from mastodon import Mastodon
|
||||||
|
|
||||||
|
Mastodon.create_app(
|
||||||
|
'backupbot',
|
||||||
|
api_base_url = 'https://your_pleoma_instance.com',
|
||||||
|
to_file = 'backupbot_clientcred.secret'
|
||||||
|
)
|
||||||
|
|
||||||
|
mastodon = Mastodon(
|
||||||
|
client_id = 'backupbot_clientcred.secret',
|
||||||
|
api_base_url = 'https://your_pleoma_instance.com'
|
||||||
|
)
|
||||||
|
|
||||||
|
mastodon.log_in(
|
||||||
|
'bot_account_username',
|
||||||
|
'bot_account_password',
|
||||||
|
to_file = 'backupbot_usercred.secret'
|
||||||
|
)
|
||||||
|
|
||||||
|
mastodon = Mastodon(
|
||||||
|
access_token = 'backupbot_usercred.secret',
|
||||||
|
api_base_url = 'https://your_pleoma_instance.com',
|
||||||
|
feature_set = 'pleroma'
|
||||||
|
)
|
||||||
|
|
||||||
|
mastodon.status_post('your_post_content')
|
29
backup.sh
29
backup.sh
|
@ -1,31 +1,26 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
source ./.env
|
source ./.env
|
||||||
|
|
||||||
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
|
echo `date +"%Y-%m-%d %H:%M:%S"` " now starting backup"
|
||||||
echo "(${TIMESTAMP}) now starting backup"
|
|
||||||
|
|
||||||
echo "1.Stopping pleroma"
|
echo "1.stop pleroma"
|
||||||
sudo systemctl stop pleroma
|
sudo systemctl stop pleroma
|
||||||
|
|
||||||
echo "2.Dumping database"
|
echo "2.dump database"
|
||||||
sudo -Hu postgres pg_dump -d $PLEROMA_DB --format=custom -f ${BACKUP_PATH}/pleroma_${TIMESTAMP}.pgdump
|
sudo -Hu postgres pg_dump -d $PLEROMA_DB --format=custom -f ${BACKUP_PATH}/pleroma.pgdump
|
||||||
|
|
||||||
echo "3.Packing uploads & static folder"
|
echo "3.pack uploads & static folder"
|
||||||
tar -czf ${BACKUP_PATH}/static_${TIMESTAMP}.tar.gz -C ${PLEROMA_PATH} static
|
tar -czf static.tar.gz --absolute-names ${PLEROMA_PATH}/static
|
||||||
tar -czf ${BACKUP_PATH}/uploads_${TIMESTAMP}.tar.gz -C ${PLEROMA_PATH} uploads
|
tar -czf uploads.tar.gz --absolute-names ${PLEROMA_PATH}/uploads
|
||||||
|
|
||||||
echo "4.Restarting pleroma"
|
echo "4.copy config file"
|
||||||
sudo systemctl start pleroma
|
|
||||||
|
|
||||||
echo "5.Copying config file"
|
|
||||||
cp ${PLEROMA_CONFIG_PATH} ${BACKUP_PATH}
|
cp ${PLEROMA_CONFIG_PATH} ${BACKUP_PATH}
|
||||||
|
|
||||||
echo "6.Backuping to remote"
|
echo "5.backup to remote"
|
||||||
./duplicacy.sh
|
./duplicacy.sh
|
||||||
|
|
||||||
echo "7.Deleting backups older than 7 days"
|
echo "6.restart pleroma"
|
||||||
find ${BACKUP_PATH} -type f -name '*.pgdump' -mtime +7 -exec rm {} \;
|
sudo systemctl start pleroma
|
||||||
|
|
||||||
echo "(${TIMESTAMP}) done!"
|
echo `date +"%Y-%m-%d %H:%M:%S"` " done!"
|
27
bot.py
27
bot.py
|
@ -1,27 +0,0 @@
|
||||||
#!/usr/bin/python
|
|
||||||
from mastodon import Mastodon
|
|
||||||
|
|
||||||
Mastodon.create_app(
|
|
||||||
'backupbot',
|
|
||||||
api_base_url='https://your_pleoma_instance.com',
|
|
||||||
to_file='backupbot_clientcred.secret'
|
|
||||||
)
|
|
||||||
|
|
||||||
mastodon = Mastodon(
|
|
||||||
client_id='backupbot_clientcred.secret',
|
|
||||||
api_base_url='https://your_pleoma_instance.com'
|
|
||||||
)
|
|
||||||
|
|
||||||
mastodon.log_in(
|
|
||||||
'bot_account_username',
|
|
||||||
'bot_account_password',
|
|
||||||
to_file='backupbot_usercred.secret'
|
|
||||||
)
|
|
||||||
|
|
||||||
mastodon = Mastodon(
|
|
||||||
access_token='backupbot_usercred.secret',
|
|
||||||
api_base_url='https://your_pleoma_instance.com',
|
|
||||||
feature_set='pleroma'
|
|
||||||
)
|
|
||||||
|
|
||||||
mastodon.status_post('your_post_content')
|
|
27
duplicacy.sh
27
duplicacy.sh
|
@ -4,10 +4,7 @@ set SECRET_ACCESS_KEY "YOUR_SECRET_ACCESS_KEY"
|
||||||
set PASSWORD "YOUR_PASSWORD"
|
set PASSWORD "YOUR_PASSWORD"
|
||||||
|
|
||||||
set timeout -1
|
set timeout -1
|
||||||
|
spawn duplicacy backup -threads 4
|
||||||
# Function to handle authentication
|
|
||||||
proc authenticate {} {
|
|
||||||
global ACCESS_KEY_ID SECRET_ACCESS_KEY PASSWORD
|
|
||||||
|
|
||||||
expect "ID"
|
expect "ID"
|
||||||
send "$ACCESS_KEY_ID\r"
|
send "$ACCESS_KEY_ID\r"
|
||||||
|
@ -17,16 +14,18 @@ proc authenticate {} {
|
||||||
|
|
||||||
expect "password"
|
expect "password"
|
||||||
send "$PASSWORD\r"
|
send "$PASSWORD\r"
|
||||||
}
|
|
||||||
|
|
||||||
# Run duplicacy backup command
|
##### (optional) Keep a revision every 7 days for revisions older than 30 days
|
||||||
spawn duplicacy backup -threads 4
|
# expect "completed"
|
||||||
authenticate
|
# spawn duplicacy prune -keep 7:30
|
||||||
expect "completed"
|
|
||||||
|
|
||||||
# Run duplicacy prune command (optional)
|
# expect "ID"
|
||||||
spawn duplicacy prune -keep 7:30
|
# send "$ACCESS_KEY_ID\r"
|
||||||
authenticate
|
|
||||||
|
|
||||||
# Allow user interaction after script completion
|
# expect "Secret"
|
||||||
interact
|
# send "$SECRET_ACCESS_KEY\r"
|
||||||
|
|
||||||
|
# expect "password"
|
||||||
|
# send "$PASSWORD\r"
|
||||||
|
|
||||||
|
expect eof
|
Loading…
Reference in a new issue