|
1 | 1 |
|
2 | | -# Debian System Backup and Restore Script |
| 2 | +# Debian System Backup and Restore Script (Version 2.0) |
3 | 3 |
|
4 | | -This repository contains a shell script to back up and restore important system elements of a Debian-based system. This is useful for creating a rollback point before making significant changes to the system. |
| 4 | +This repository contains a shell script for backing up and restoring key system elements of a Debian-based system. It is useful for creating a recovery point before making significant changes to the system. |
5 | 5 |
|
6 | 6 | ## Features |
7 | 7 | - Backs up the list of installed packages. |
8 | 8 | - Backs up configuration files in `/etc`. |
9 | | -- Optional: Backs up the entire filesystem (excluding the backup directory itself). |
| 9 | +- Optionally: Backs up the entire file system (with configurable exclusions). |
10 | 10 | - Provides a restore function to revert the system to the saved state. |
| 11 | +- Logs all actions in detail. |
11 | 12 |
|
12 | | -## Prerequisites |
| 13 | +## Requirements |
13 | 14 | - A Debian-based system (e.g., Debian, Ubuntu). |
14 | 15 | - Sufficient disk space for the backup. |
15 | 16 |
|
16 | 17 | ## Usage |
17 | 18 |
|
18 | | -### 1. Clone the Repository |
| 19 | +### 1. Clone the repository |
19 | 20 | Clone this repository to your local machine: |
20 | 21 | ```sh |
21 | 22 | git clone https://github.com/VolkanSah/Debian-System-Backup-and-Restore-Script |
22 | 23 | cd Debian-System-Backup-and-Restore-Script |
23 | 24 | ``` |
24 | 25 |
|
25 | | -### 2. Make the Script Executable |
26 | | -Ensure the script has execute permissions: |
| 26 | +### 2. Make the script executable |
| 27 | +Ensure the script has execution permissions: |
27 | 28 | ```sh |
28 | 29 | chmod +x backup_script.sh |
29 | 30 | ``` |
30 | 31 |
|
31 | | -### 3. Run the Backup Script |
32 | | -To create a backup, run the script without any arguments: |
| 32 | +### 3. Run the backup script |
| 33 | +To create a backup, run the script with the `backup` argument: |
33 | 34 | ```sh |
34 | | -./backup_script.sh |
| 35 | +./backup_script.sh backup |
35 | 36 | ``` |
| 37 | +For a full file system backup: |
| 38 | +```sh |
| 39 | +./backup_script.sh backup full |
| 40 | +``` |
| 41 | + |
36 | 42 | This will: |
37 | | -- Create a backup directory with a timestamp. |
| 43 | +- Create a timestamped backup directory. |
38 | 44 | - Save the list of installed packages to `installed_packages.list`. |
39 | | -- Compress and save configuration files from `/etc` to `etc_backup.tar.gz`. |
40 | | -- Optionally, you can uncomment the lines in the script to back up the entire filesystem. |
| 45 | +- Compress and store configuration files from `/etc` into `etc_backup.tar.gz`. |
| 46 | +- Optionally back up the entire file system (if "full" is specified). |
41 | 47 |
|
42 | | -### 4. Restore from a Backup |
| 48 | +### 4. Restore from a backup |
43 | 49 | To restore the system from a backup, run the script with the `restore` argument and the path to the backup directory: |
44 | 50 | ```sh |
45 | 51 | ./backup_script.sh restore /path/to/backup_directory |
46 | 52 | ``` |
| 53 | +For a full system restore: |
| 54 | +```sh |
| 55 | +./backup_script.sh restore /path/to/backup_directory full |
| 56 | +``` |
| 57 | + |
47 | 58 | This will: |
48 | 59 | - Restore the list of installed packages. |
49 | 60 | - Extract and restore configuration files from `etc_backup.tar.gz`. |
50 | | -- Optionally, uncomment the lines to restore the entire filesystem. |
| 61 | +- Optionally restore the entire file system (if "full" is specified). |
51 | 62 |
|
52 | 63 | ## Script Details |
53 | 64 |
|
54 | | -### Backup Script |
55 | | -```bash |
56 | | -#!/bin/bash |
57 | | - |
58 | | -# Create backup directory |
59 | | -BACKUP_DIR="/backup/$(date +%Y%m%d_%H%M%S)" |
60 | | -mkdir -p "$BACKUP_DIR" |
61 | | - |
62 | | -# Save the list of installed packages |
63 | | -dpkg --get-selections > "$BACKUP_DIR/installed_packages.list" |
64 | | -echo "Package list saved to $BACKUP_DIR/installed_packages.list" |
65 | | - |
66 | | -# Backup configuration files |
67 | | -tar czf "$BACKUP_DIR/etc_backup.tar.gz" /etc |
68 | | -echo "Configuration files saved to $BACKUP_DIR/etc_backup.tar.gz" |
69 | | - |
70 | | -# Optional: Backup the entire filesystem (can consume a lot of space) |
71 | | -# tar czf "$BACKUP_DIR/full_backup.tar.gz" --exclude="$BACKUP_DIR" / |
72 | | - |
73 | | -# Backup complete |
74 | | -echo "Backup complete. All important files are saved in $BACKUP_DIR." |
75 | | - |
76 | | -# Restore function |
77 | | -restore() { |
78 | | - BACKUP_DIR="$1" |
79 | | - if [ -z "$BACKUP_DIR" ]; then |
80 | | - echo "Please specify the backup directory." |
81 | | - exit 1 |
82 | | - fi |
83 | | - |
84 | | - # Restore the list of installed packages |
85 | | - sudo dpkg --set-selections < "$BACKUP_DIR/installed_packages.list" |
86 | | - sudo apt-get -y dselect-upgrade |
87 | | - echo "Package list restored." |
88 | | - |
89 | | - # Restore configuration files |
90 | | - tar xzf "$BACKUP_DIR/etc_backup.tar.gz" -C / |
91 | | - echo "Configuration files restored." |
92 | | - |
93 | | - # Optional: Restore the entire filesystem |
94 | | - # tar xzf "$BACKUP_DIR/full_backup.tar.gz" -C / |
95 | | -} |
96 | | - |
97 | | -# Automatic restore if an argument is provided |
98 | | -if [ "$1" == "restore" ]; then |
99 | | - restore "$2" |
100 | | -fi |
101 | | -``` |
| 65 | +The updated script offers the following improvements: |
| 66 | +- Detailed logging of all actions. |
| 67 | +- Configurable options for important settings. |
| 68 | +- An exclusion list for full backups. |
| 69 | +- Improved structure with separate functions for backup and restore. |
| 70 | +- Flexible options for normal and full backup/restore. |
| 71 | +- Enhanced error handling and checks. |
102 | 72 |
|
103 | 73 | ## Recommendations |
104 | | -- **Error Handling**: Add error handling and checks for available disk space before proceeding with the backup. |
105 | | -- **Notifications**: Integrate notifications (e.g., via email) to inform you upon successful backup or restoration. |
| 74 | +- **Error Handling**: The script now includes basic error handling. Consider adding further checks, such as for available disk space. |
| 75 | +- **Notifications**: Integrate notifications (e.g., via email) to inform you of successful backups or restores. |
106 | 76 |
|
107 | 77 | ## License |
108 | | -This project is licensed under the GPLv3 License. See the `LICENSE` file for details. |
| 78 | +This project is licensed under the GPLv3 license. See the `LICENSE` file for details. |
109 | 79 |
|
110 | 80 | ## Contributing |
111 | | -Contributions are welcome! Please open an issue or submit a pull request for any improvements or suggestions. |
| 81 | +Contributions are welcome! Please open an issue or submit a pull request for improvements or suggestions. |
112 | 82 |
|
113 | 83 | ## Contact |
114 | | -For any questions or support, please open an issue in the repository. |
| 84 | +For questions or support, please open an issue in the repository. |
115 | 85 |
|
116 | | -## Your Support |
117 | | -If you find this project useful and want to support it, there are several ways to do so: |
| 86 | +## Supporting the Project |
| 87 | +If you find this project helpful and would like to support it, there are several ways to do so: |
118 | 88 |
|
119 | | -- If you find the white paper helpful, please ⭐ it on GitHub. This helps make the project more visible and reach more people. |
120 | | -- Become a Follower: If you're interested in updates and future improvements, please follow my GitHub account. This way you'll always stay up-to-date. |
121 | | -- Learn more about my work: I invite you to check out all of my work on GitHub and visit my developer site https://volkansah.github.io. Here you will find detailed information about me and my projects. |
| 89 | +- If you find this script useful, please give it a ⭐ on GitHub. This helps make the project more visible and reach more people. |
| 90 | +- Follow me: If you're interested in updates and future improvements, please follow my GitHub account to stay informed. |
| 91 | +- Learn more about my work: I invite you to view all my work on GitHub and visit my developer website at https://volkansah.github.io. There, you'll find detailed information about me and my projects. |
122 | 92 | - Share the project: If you know someone who could benefit from this project, please share it. The more people who can use it, the better. |
123 | | -**If you appreciate my work and would like to support it, please visit my [GitHub Sponsor page](https://github.com/sponsors/volkansah). Any type of support is warmly welcomed and helps me to further improve and expand my work.** |
| 93 | + |
| 94 | +**If you appreciate my work and would like to support it, please visit my [GitHub Sponsor page](https://github.com/sponsors/volkansah). Any kind of support is greatly appreciated and helps me improve and expand my work.** |
124 | 95 |
|
125 | 96 | Thank you for your support! ❤️ |
126 | 97 |
|
|
0 commit comments