Skip to content

Instantly share code, notes, and snippets.

@jsfan3

jsfan3/backup.sh Secret

Created January 2, 2020 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsfan3/cb1b18529c4eebbde5392286c2e155d3 to your computer and use it in GitHub Desktop.
Save jsfan3/cb1b18529c4eebbde5392286c2e155d3 to your computer and use it in GitHub Desktop.
Example of how to backup your Netbeans projects in Linux
#!/bin/bash
OUTPUT_FILE_NAME="Backup_$(date +%Y%m%d_%H%M%S).7z"
OUTPUT_FILE="/home/yourname/Backups/${OUTPUT_FILE_NAME}"
DBPASSWORD='yourDBpassword';
# In this example, I assume that all your Netbeans project are placed in the following directory
cd /home/yourname/Projects/
# In this example, I assume that AppServer is a Spring Boot Netbeans project, so the "target" dir can be removed
rm -fR /home/yourname/Projects/AppServer/target/
# When you do backups, you can remove all "buld" and "dist" folders of your Netbeans projects
find -depth -name build -type d -exec rm -fR "{}" \;
find -depth -name dist -type d -exec rm -fR "{}" \;
# I include a backup of the database
mysqldump -uroot -p${DBPASSWORD} yourProjectName > yourProjectName.sql
# To restore:
# mysql -uroot -p yourProjectName < yourProjectName.sql
# I use 7zip because it offers a very good compression for sources, compared with normal zip
7z a -mhe=on -t7z -mx9 -ms=on -r ${OUTPUT_FILE} ./
# After the backup, you can remove the mysql dump
rm -f yourProjectName.sql
# Optionally, you can also copy your backup to a different folder
cp ${OUTPUT_FILE} /media/anotherSupport/BackupSources/${OUTPUT_FILE_NAME}
sync
echo ""
echo "Sync executed"
echo ""
read -p "Sources cleaned and backup created... press ENTER to close";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment