This repository contains a shell script to perform weekly maintenance tasks on a Debian server. The script clears various caches, removes unused Docker data, cleans the APT cache, and performs other housekeeping tasks to ensure optimal server performance.
- Clear PageCache, dentries, and inodes
- Remove unused Docker images, containers, volumes, and networks
- Clean APT cache and remove unnecessary packages
- Clear systemd journal logs older than 7 days
- Clear temporary files in
/tmp
and/var/tmp
-
Clone the repository:
git clone https://github.com/mrxehmad/Server-Maintenance.git cd Server-Maintenance
-
Copy the script to
/usr/local/bin
:sudo cp weekly_maintenance.sh /usr/local/bin/
-
Make the script executable:
sudo chmod +x /usr/local/bin/weekly_maintenance.sh
-
Set up the cron job:
sudo crontab -e
Add the following line to the crontab file to run the script every Sunday at 2 AM:
0 2 * * 0 /usr/local/bin/weekly_maintenance.sh > /var/log/weekly_maintenance.log 2>&1
To verify that the cron job is set up correctly, you can list the current cron jobs:
sudo crontab -l
You can manually run the script to test it:
sudo /usr/local/bin/weekly_maintenance.sh
The cron job redirects both stdout and stderr to a log file (/var/log/weekly_maintenance.log
). Check this file to see the output of the script and troubleshoot any issues.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.