-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jose Hbez
committed
Apr 7, 2024
1 parent
6ee1e52
commit c727e0b
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#! /bin/bash | ||
|
||
function help(){ | ||
echo " | ||
Usage full: large-backup.sh [options...] | ||
arg1:mode - [full] create backup include filestore and database | ||
arg2:data_dir - [~/.local/share/Odoo] Filestore location | ||
arg3:pg_hostname | ||
arg4:pg_port | ||
arg5:pg_user | ||
arg6:pg_pass | ||
arg7:pg_db | ||
arg8:backup_dir - [./] | ||
Example: | ||
large-backup.sh full /home/$USER/.local/share/Odoo localhost 4390 user pass db /backups | ||
" | ||
} | ||
function full(){ | ||
data_dir="$1" | ||
pg_hostname="$2" | ||
pg_port="$3" | ||
pg_user="$4" | ||
pg_pass="$5" | ||
pg_db="$6" | ||
backup_dir="${7:-/tmp}" | ||
|
||
export PGPASSWORD="$pg_pass" | ||
|
||
filestore="$data_dir/filestore/$pg_db" | ||
if [ ! -d "$filestore" ]; then | ||
echo "Filestore no exists $filestore" | ||
exit 0 | ||
fi | ||
echo "Filestore: $filestore" | ||
|
||
tmp_dir="$backup_dir/$pg_db" | ||
#if [ -d $tmp_dir ]; then | ||
# rm -r $tmp_dir | ||
#fi | ||
mkdir -p "$tmp_dir" | ||
echo "Backup tmp: $tmp_dir" | ||
|
||
tmp_dir_dump="$tmp_dir/dump.sql" | ||
backup_file="$pg_db-$(date +"%Y%m%d%H%M").tar.gz" | ||
|
||
echo "Dump: $tmp_dir_dump" | ||
|
||
pg_dump -v --host "$pg_hostname" --port "$pg_port" --username "$pg_user" -w -F p "$pg_db" > "$tmp_dir_dump" | ||
|
||
cp -r $filestore $tmp_dir/ | ||
cd $tmp_dir | ||
tar czvf "$backup_file" $(basename $filestore) $(basename $tmp_dir_dump) | ||
cd - | ||
rm -vr "$tmp_dir/$pg_db" | ||
rm $tmp_dir_dump | ||
echo "Backup file: $backup_file" | ||
} | ||
|
||
|
||
case $1 in | ||
"full") | ||
full "$2" "$3" "$4" "$5" "$6" "$7" "$8" | ||
;; | ||
|
||
*) | ||
help | ||
;; | ||
esac |