Compare commits

...
3 Commits
Author SHA1 Message Date
JotaOdiceu 6cf5a08187 feat(backup): add Restic S3 backup recipes
Introduce comprehensive recipes for Restic-based S3 backups.
Covers installation, S3 repository configuration, automated backup job creation, and restoration of files.
2026-07-04 19:26:01 -03:00
JotaOdiceu 8266e47963 refactor(samba): streamline install and configure recipes
Reorder and clarify Samba setup instructions across recipes.
Remove redundant "Configure Samba" section from install.
Consolidate "Create Samba User" in install recipe.
Relocate service verification to post-restart in configure recipe.
Correct 'smbd --version' command.
2026-07-04 17:19:40 -03:00
JotaOdiceu 988715b433 docs(samba): add install, configure, and uninstall recipes 2026-07-04 15:33:16 -03:00
7 changed files with 618 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
# Install Restic
This recipe installs Restic, a fast, secure, and encrypted backup tool.
## Install Package
```bash
sudo apt update
sudo apt install -y restic
```
## Verify Installation
```bash
restic version
```
Expected output:
```text
restic x.x.x compiled with go...
```
## Verify Binary Location
```bash
which restic
```
Expected output:
```text
/usr/bin/restic
```
## Troubleshooting
### Command not found
Verify that the package is installed.
```bash
dpkg -l | grep restic
```
If it is not installed, repeat the installation step.
+115
View File
@@ -0,0 +1,115 @@
# Configure Restic S3 Repository
This recipe configures an encrypted Restic repository stored in an S3-compatible object storage.
## Supported Providers
Restic supports any S3-compatible storage provider, including:
- MinIO
- Amazon S3
- Cloudflare R2
- Oracle Cloud Object Storage
## Create Environment File
```bash
sudo nano /etc/restic.env
```
Example:
```bash
export AWS_DEFAULT_REGION=YOUR_BUCKET_REGION_OR_AUTO
export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY
export RESTIC_PASSWORD=CHANGE_ME
export RESTIC_REPOSITORY=s3:https://<S3_ENDPOINT>/<BUCKET>/restic/<PREFIX>
```
Replace:
- `<S3_ENDPOINT>` with your provider endpoint.
- `<BUCKET>` with your bucket name.
- `<PREFIX>` with a prefix for backups (e.g. machine name)
Protect the file:
```bash
sudo chmod 600 /etc/restic.env
sudo chown root:root /etc/restic.env
```
## Common Endpoint Examples
| Provider | Endpoint |
|---------------------|-------------------------------------------------------------|
| MinIO | `minio.example.com` |
| Amazon S3 | `s3.amazonaws.com` |
| Cloudflare R2 | `<ACCOUNT_ID>.r2.cloudflarestorage.com` |
| Oracle Cloud | `<NAMESPACE>.compat.objectstorage.<REGION>.oraclecloud.com` |
## Example Configurations
Cloudflare R2:
```bash
RESTIC_REPOSITORY=s3:https://xxxxxxxx.r2.cloudflarestorage.com/backups/restic
```
Oracle Cloud:
```bash
RESTIC_REPOSITORY=s3:https://mynamespace.compat.objectstorage.sa-saopaulo-1.oraclecloud.com/backups/restic
```
## Load Environment
```bash
source <(sudo cat /etc/restic.env)
```
## Initialize Repository
```bash
restic init
```
Expected output:
```text
created restic repository
```
If the repository already exists:
```text
repository master key and config already initialized
```
## Verify Repository
```bash
restic snapshots
```
Expected output:
```text
no snapshots found
```
## Troubleshooting
### Repository already initialized
Expected if repository exists.
### Wrong password
Verify the value of:
```bash
echo $RESTIC_PASSWORD
```
+114
View File
@@ -0,0 +1,114 @@
# Create Automatic Backup Job
This recipe creates a daily backup job using Restic and systemd.
## Create Backup Script
```bash
sudo nano /usr/local/bin/restic-backup.sh
```
Contents:
```bash
#!/usr/bin/env bash
set -e
source /etc/restic.env
restic backup <PATH>
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3 --prune
```
Replace:
- `<PATH>` with the folder path you want to backup (e.g. `/srv/samba`)
## Make Script Executable
```bash
sudo chmod +x /usr/local/bin/restic-backup.sh
```
## Load Environment
```bash
source <(sudo cat /etc/restic.env)
```
## Test Backup
```bash
sudo /usr/local/bin/restic-backup.sh
```
## Verify Snapshot
```bash
restic snapshots
```
Expected output:
```text
ID Time Host
----------------------------------------
xxxxxxxx YYYY-MM-DD HH:MM hostname
```
## Automate with Cron
Edit root crontab.
```bash
sudo crontab -e
```
Add:
```cron
0 2 * * * /usr/local/bin/restic-backup.sh
```
## Verify Cron
```bash
sudo crontab -l
```
Expected output should contain:
```cron
0 2 * * * /usr/local/bin/restic-backup.sh
```
## Troubleshooting
### Repository not found
Verify:
```bash
echo $RESTIC_REPOSITORY
```
### Authentication failed
Verify the configured S3 credentials.
```bash
echo $AWS_ACCESS_KEY_ID
```
```bash
echo $AWS_SECRET_ACCESS_KEY
```
### Wrong password
Verify:
```bash
echo $RESTIC_PASSWORD
```
+95
View File
@@ -0,0 +1,95 @@
# Restore Backup
This recipe restores files from a Restic repository.
## Load Environment
```bash
source <(sudo cat /etc/restic.env)
```
## List Snapshots
```bash
restic snapshots
```
Expected output:
```text
ID Time Host
----------------------------------------
xxxxxxxx YYYY-MM-DD HH:MM
```
## Restore Latest Snapshot
```bash
restic restore latest --target /tmp/restore
```
## Restore Specific Snapshot
Replace `<snapshot-id>` with the desired snapshot.
```bash
restic restore <snapshot-id> --target /tmp/restore
```
## Restore a Single Directory
```bash
restic restore latest --target /tmp/restore --include <PATH>
```
Replace:
- `<PATH>` with the folder path you want to restore (e.g. `/srv/samba`)
## Verify Restored Files
```bash
ls -la /tmp/restore
```
## Verify Repository Integrity
```bash
restic check
```
Expected output:
```text
no errors were found
```
## Troubleshooting
### Repository not found
Verify:
```bash
echo $RESTIC_REPOSITORY
```
### Authentication failed
Verify the configured S3 credentials.
```bash
echo $AWS_ACCESS_KEY_ID
```
```bash
echo $AWS_SECRET_ACCESS_KEY
```
### Wrong password
Verify:
```bash
echo $RESTIC_PASSWORD
```
+76
View File
@@ -0,0 +1,76 @@
# Install Samba
This recipe installs Samba on Ubuntu, enables the required services, and configures a basic file share.
## Install Packages
```bash
sudo apt update
sudo apt install -y samba
```
## Verify Installation
```bash
sudo smbd --version
```
Expected output:
```text
Version 4.x.x
```
## Enable Services
```bash
sudo systemctl enable smbd
sudo systemctl enable nmbd
sudo systemctl start smbd
sudo systemctl start nmbd
```
## Verify Services
```bash
systemctl status smbd --no-pager
systemctl status nmbd --no-pager
```
Both services should be reported as **active (running)**.
## Restart Samba
```bash
sudo systemctl restart smbd
sudo systemctl restart nmbd
```
## Configure Firewall (Optional)
If UFW is enabled:
```bash
sudo ufw allow samba
```
## Verify Listening Ports
```bash
sudo ss -tulpn | grep smb
```
Expected output should include ports **139** and **445**.
## Create Samba User
```bash
sudo smbpasswd -a <username>
sudo smbpasswd -e <username>
```
List configured Samba users.
```bash
sudo pdbedit -L
```
+89
View File
@@ -0,0 +1,89 @@
# Configure Samba Share
This recipe configures a basic Samba file share.
## Backup Existing Configuration
```bash
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
```
## Create Configuration
Replace the existing configuration.
```bash
sudo tee /etc/samba/smb.conf >/dev/null <<'EOF'
[global]
workgroup = WORKGROUP
server string = Samba Server
security = user
map to guest = Bad User
[Share]
path = /srv/samba
browseable = yes
writable = yes
guest ok = no
read only = no
create mask = 0664
directory mask = 0775
EOF
```
## Create Share Directory
```bash
sudo mkdir -p /srv/samba
```
## Configure Permissions
Replace `<username>` with your Linux username.
```bash
sudo chown -R <username>:<username> /srv/samba
sudo chmod -R 775 /srv/samba
```
## Validate Configuration
```bash
testparm
```
Expected output:
```text
Loaded services file OK.
```
## Restart Samba
```bash
sudo systemctl restart smbd
sudo systemctl restart nmbd
```
## Verify Services
```bash
systemctl status smbd --no-pager
systemctl status nmbd --no-pager
```
Both services should be reported as **active (running)**.
## Verify Share
```bash
smbclient -L localhost -U <username>
```
Expected output should include:
```text
Sharename Type
--------- ----
Share Disk
```
+83
View File
@@ -0,0 +1,83 @@
# Uninstall Samba
This recipe completely removes Samba from Ubuntu, including services, packages, and configuration files.
## Stop Services
```bash
sudo systemctl stop smbd
sudo systemctl stop nmbd
```
## Disable Services
```bash
sudo systemctl disable smbd
sudo systemctl disable nmbd
```
## Remove Packages
```bash
sudo apt purge -y samba samba-common samba-common-bin smbclient
sudo apt autoremove -y
```
## Remove Configuration
```bash
sudo rm -rf /etc/samba
sudo rm -rf /var/lib/samba
sudo rm -rf /var/cache/samba
sudo rm -rf /var/log/samba
```
## Remove Firewall Rule (Optional)
If UFW was configured:
```bash
sudo ufw delete allow samba
```
## Remove Shared Directories (Optional)
Only run this if the directory was created exclusively for Samba and does not contain important files.
```bash
sudo rm -rf /srv/samba
```
## Verify Removal
Check that the package is no longer installed.
```bash
dpkg -l | grep samba
```
No packages should be listed.
Verify that the service no longer exists.
```bash
systemctl status smbd
```
Expected output:
```text
Unit smbd.service could not be found.
```
Verify that the configuration directory has been removed.
```bash
ls /etc/samba
```
Expected output:
```text
ls: cannot access '/etc/samba': No such file or directory
```