removed restic role

This commit is contained in:
tolerryan
2024-10-17 23:32:04 -05:00
parent 04fcf592dc
commit 871803165a

View File

@@ -4,8 +4,6 @@
become: yes become: yes
remote_user: ansible remote_user: ansible
gather_facts: false gather_facts: false
roles:
- {role: roles-ansible.restic , tags: restic}
vars: vars:
restic_create_schedule: true restic_create_schedule: true
@@ -22,14 +20,122 @@
scheduled: true scheduled: true
schedule_oncalendar: '*-*-* 01:00:00' schedule_oncalendar: '*-*-* 01:00:00'
tasks: tasks:
- name: Create Restic user
user:
name: restic
uid: 2001
group: user
state: present
create_home: yes
home: /home/restic
shell: /bin/bash
- name: Add key for Restic user
ansible.posix.authorized_key:
user: restic
state: present
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOsDIrV6QIMtpJFNpZEgHnkYgFC6OXMJQFc1JqrnpCzY fake@gmail.com"
- name: Copy restic.sh
copy:
dest: /home/restic/restic.sh
content: |
#!/bin/bash
# Check if a flag was passed
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 [--backup] [--forget] [--check]"
exit 1
fi
# Initialize variables
backup=false
forget=false
check=false
password=($cat ./.resticpassword)
# Parse arguments
for arg in "$@"
do
case $arg in
--backup)
backup=true
;;
--forget)
forget=true
;;
--check)
check=true
;;
*)
echo "Unknown argument: $arg"
exit 1
;;
esac
done
# Execute Restic commands based on flags
if $backup; then
echo "Backing up... to misamisa"
echo "Date: $(date '+%Y-%m-%d_%H-%M-%S')" # Add your Restic backup command here
restic --password-file ./.resticpassword -r sftp:misamisa://home/restic/$(hostname) backup ./
if [ $? -eq 0 ]; then
# If the exit status is 0 (success), send a success message
./discord.sh "$(hostname) backup complete"
else
# If the exit status is not 0 (failure), send a failure message
./discord.sh "$(hostname) Backup has failed"
fi
echo "Backup completed $(date '+%Y-%m-%d_%H-%M-%S')"
fi
if $forget; then
echo "Removing old backups..."
# Add your Restic forget command here
restic --password-file ./.resticpassword -r sftp:misamisa://home/restic/$(hostname) forget --keep-within-daily 7d --keep-within-weekly 1m --keep-within-monthly 1y
if [ $? -eq 0 ]; then
# If the exit status is 0 (success), send a success message
./discord.sh "$(hostname) forget command completed successfully"
else
# If the exit status is not 0 (failure), send a failure message
./discord.sh "$(hostname) forget command has failed"
fi
fi
if $check; then
echo "Checking backups..."
# Add your Restic check command here
restic --password-file ./.resticpassword -r sftp:misamisa://home/restic/$(hostname) check --read-data
if [ $? -eq 0 ]; then
# If the exit status is 0 (success), send a success message
./discord.sh "$(hostname) Restic Verification complete"
else
# If the exit status is not 0 (failure), send a failure message
./discord.sh "$(hostname) Restic Verification failed!! there is an issue"
fi
restic --password-file ./.resticpassword -r sftp:misamisa://home/restic/$(hostname) unlock
fi
owner: restic
group: restic
mode: '0644'
- name: Copy discord.sh
copy:
dest: /heme/restic/discord.sh
content: {{ discord_webhook }}}
owner: restic
group: restic
mode: '0644'
- name: Create SSH config file - name: Create SSH config file
copy: copy:
dest: /home/docker/.ssh/config dest: /home/restic/.ssh/config
content: | content: |
Hostname misamisa.duckdns.org Hostname misamisa.duckdns.org
Port 25456 Port 25456
User restic User restic
IdentityFile vm IdentityFile vm
owner: docker owner: restic
group: docker group: restic
mode: '0640' mode: '0644'