folder2archive/README.md

74 lines
2.2 KiB
Markdown
Raw Normal View History

2023-04-18 20:58:10 +02:00
<img src="https://git.moelle.space/hxcde/folder2archive/raw/branch/main/f2a.png" width="250" />
2023-04-18 20:58:02 +02:00
2023-04-18 20:33:41 +02:00
> Daily Folder Backup and Rotation for Linux <br>
>I use this to create archives of my website every day
2023-04-08 21:40:28 +02:00
2023-04-08 21:42:38 +02:00
## Key Features:
- Daily automated backups of a specified folder using the zip utility.
- Date-appended archive file names for easy identification.
- Automatic removal of backups older than 14 days.
- Scheduled execution using cron for a hands-off approach.
2023-04-08 21:40:28 +02:00
## Explanation:
2023-04-08 21:41:16 +02:00
- The script sets the source directory (SOURCE_DIR) that will be zipped and the archive directory (ARCHIVE_DIR) where the zipped files will be stored.
- It creates a timestamp in the format YYYY-MM-DD and stores it in the DATE variable.
- The zip command is used to create the zipped archive and append the date to the file name.
2023-04-12 01:49:43 +02:00
- The find command is used to delete files older than 14 days in the archive directory. (edit in the script as needed)
2023-04-08 21:41:16 +02:00
- The cron entry schedules the script to run daily at 13:00 (1 PM).
2023-04-08 21:44:08 +02:00
2023-04-18 20:06:24 +02:00
## Automatic installation
2023-04-18 20:04:58 +02:00
2023-04-18 20:07:40 +02:00
Paste the script in your machines console.
2023-04-18 20:03:41 +02:00
```bash
2023-04-18 20:41:49 +02:00
sh -c "$(curl -L http://script.moelle.space/folder2archive)"
2023-04-18 20:03:41 +02:00
```
2023-04-18 20:10:11 +02:00
2023-04-18 20:26:41 +02:00
## Settings
2023-04-18 20:13:06 +02:00
<details>
<summary>Change the day count </summary>
<br>
2023-04-18 20:17:19 +02:00
Edit the file zip_folder_daily.sh `(If you used automatic install it's in /opt)` and change the day number in line 16.
2023-04-18 20:29:51 +02:00
<br> If you want 30 days, it's `30 minus 1`, so `29`
2023-04-18 20:27:14 +02:00
```bash
2023-04-18 20:28:53 +02:00
find "${ARCHIVE_DIR}" -name "folder_*.zip" -mtime +13 -exec rm {} \;
2023-04-18 20:27:14 +02:00
```
2023-04-18 20:29:10 +02:00
Example: Chamge the `13` to `29`
2023-04-18 20:27:14 +02:00
```bash
2023-04-18 20:28:53 +02:00
find "${ARCHIVE_DIR}" -name "folder_*.zip" -mtime +29 -exec rm {} \;
2023-04-18 20:27:14 +02:00
```
2023-04-18 20:20:11 +02:00
</details>
<details>
<summary>Change the schedule </summary>
<br>
2023-04-18 20:25:51 +02:00
Edit the cronjob with `crontab -e`
```bash
0 13 * * * sh /path/to/script/zip_folder_daily.sh
```
If you need help to configure the crontab, check this site https://crontab.guru/
2023-04-18 20:26:41 +02:00
</details>
## Manual installation
<details>
<summary>Installation </summary>
<br>
Install git and zip
```bash
apt install git zip -y
```
Clone the repository
```bash
2023-04-18 20:39:42 +02:00
git clone https://git.moelle.space/hxcde/folder2archive.git
2023-04-18 20:26:41 +02:00
```
2023-04-18 20:31:34 +02:00
Edit the zip_folder_daily.sh file
<br>
2023-04-18 20:26:41 +02:00
Add the following to cron to automate Backup
```bash
0 13 * * * sh /path/to/script/zip_folder_daily.sh
```
2023-04-18 20:04:47 +02:00
</details>