Protect harddisk-based backup from accidental removal
If you store a backup on hard disk, the risk of rm -rf does exists.
Use chattr command changes the file attributes on a Linux second extended file system so that you will stay away from accidentally removing your backup files with rm -rf.
chattr command write protect the backup directory so that no one can delete it (including root). This is also known as making file immutable. For example your backup directory is /backup, type the following command to write protect directory /backup (only root can set or remove these flags):
# chattr -R +i /backup
To remove immutable flag, type the following command:
# chattr -R -i /backup
If you are using FreeBSD use chflags command to setup immutable flag:
# chflags -R schg /backup
To remove immutable flag, type the following command:
# chflags -R noschg /backup
These commands will keep you from accidentally removing your backup files with rm -rf ![]()
E-mail this to a Friend
Printable Version
You may also be interested in other helpful articles:
- Why back up UNIX or Linux (or windows) systems?
- Take action or execute a command based upon shell script name
- Rotate FTP Backup Using a Shell Script
- Why my Linux server ext3 filesystem go read-only?
- How to MySQL backup and data recovery with mysql-zrm
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!


Recent Comments
Yesterday ~ 12 Comments
Yesterday ~ 8 Comments
Yesterday ~ 185 Comments
Yesterday ~ 15 Comments
Yesterday ~ 3 Comments