https://www.atlassian.com/fr/git/tutorials
https://git-scm.com/docs
TOC
| chapter | ||
|---|---|---|
| REFERENCE | - ADD | - MERGE |
| USED | - ARCHIVE | - PULL |
| URL | - BRANCH | - PUSH |
| VALUES | - CHECKOUT | - REMOTE |
| GPG | - CLONE | - REBASE |
| GITIGNORE | - COMMIT | - RESET |
| TRICKS | - FETCH | - STASH |
| CONFIG | - LOG | - SUBMODULE |
| - LOG | - SWITCH | |
| - LOG | - TAG |
USEFULL OPTIONS
git -C <path> <commands> # launch git commands in <path> repo
REFERENCE
URL
https://<fqdn>/<user>/<project> # https://github.com/aguytech/Shaarli
git@<fqdn>:<user>/<project>.git # git@github.com:aguytech/Shaarli.git
VALUES
git rev-parse --symbolic-full-name --abbrev-ref @{upstream} # print value for upstream
git rev-parse --symbolic-full-name --abbrev-ref @{push} # print value for push
git for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads # show all upstream
git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)" # idem
git for-each-ref --format='%(refname:short) <- %(push:short)' refs/heads # show all upstream
git for-each-ref --format='%(push:short)' "$(git symbolic-ref -q HEAD)" # idem
USED
ADD
git add -i / --interactive # add with interactively mode
git add -u / --update # Update the index for already referred files (just where it already has an entry matching <pathspec>
gi add -A / --all / --no-ignore-removal # add all files
ARCHIVE
git archive -l # list available formats
git archive --format tar.gz -9 -o "$(git br --show-current).$(date +%s).tar.gz" <branch> # create an archive from local <branch> with best compression -9 & in format tar.gz
BRANCH
https://stackoverflow.com/questions/11266478/git-add-remote-branch
list
git branch / git br # print list of local branches
git br -v # print informations about local branches
git br -vv # print full information about local branches
git branch -a -vv # print full information about all branches
git br --show-current # show name of current branch
git br -r # print list of remote branches for all repositories
git br -rlv <remote>/<pattern> # list remote branches for <remote> repository & with name matched <pattern>
create
git br <branch> # create a local branch
git br <branch> <remote>/<remote_branch> # create local branch from remote
git push <upstream> <branch> # create remote branch from existing local one
delete
git br -d <branch> # delete local branch
git br -rd <remote>/<branch> # delete remote branch
rename
# local
git br -m <old-branch> <new-branch># rename local branch
# remote
git br -m <old-branch> <new-branch># rename local branch
git push origin --delete <old-branch>
git push origin <new-branch>
attach to upstream
git fetch # retrieves upsteram branches if already exists
git br -u <upstream>/<remote_branch> <branch> # attach a local branch to remote existing one
git br --set-upstream-to=<upstream>/<remote_branch> <branch>
CHECKOUT
git co -b <branch> # create a branch from HEAD and switch to it
git co -t <repo>/<branch> -b <branch> # create a local branch from <repo>/<branch> and set upstream
git co --orphan=<branch> # create an orphan branch (whithout history)
git co --orphan=<branch> # create an orphan branch (whithout history)
git co --detach -b <branch> # check out a commit for inspection and discardable experiments
CLONE
git clone <url> # clone a repository
git clone <url> <path> # clone a repository and change path name to <path>
git clone -b <branch> <url> # clone only one branch from repository
git clone -b v0.11-snippets --single-branch --no-tags git@github.com:aguytech/Shaarli.git shaarli-snippets # clone from a repository a single branch
COMMIT
# amend
git commit --amend --no-edit # amends a commit without changing its commit message
git commit --amend -m "message" # amends a commit with a new message
DIFF
git diff <file> # view the changes you made relative to the index (staging area for the next commit)
git diff HEAD README.md <file> # view the changes between index and HEAD
git diff @{u} # view the changes between local and upstream branch
FETCH
git fetch upstream : Get informations from upstream for all branches
git fetch upstream <branch> : Get informations from upstream only for the branch
CONFIG
# amend
git config --global init.defaultBranch main # set main as the default branch
git config <variable> # show variable and his value
git config --global core.editor vim # set selected editor
git config -l # list all config variables
git config -l --show-origin # list all config variables with their origins
git config -l --name-only # list all names of system config variables
git config -l --local # list all config variables defined for user
git config -l --global # list all global config variables for global users
git config -l --system # list all system config variables for system
LOG
git log # show logs
git log HEAD~2 <repo>/<branch> # show after the last 2nd commits
git log -3 <repo>/<branch> # show only last 3 lines of logs
git log --pretty=format:'%h' -n1 <repo>/<branch> # show short sha of last commit
git log --name-only # with file names
git log --name-status # with file names with its status
git log --stat # with file names with its statisticals
git reflog # show logs with a reference (sha) view
MERGE
git merge -m "message" <branch> # merge branch with actual one with a message to committing
git merge --allow-unrelated-histories <branch> # allows to merge branch with no common history
PULL
If you tried a pull which resulted in complex conflicts and would want to start over, you can recover with git reset
git pull # Update actual local branch from current remote
git pull <remote> # Update actual local branch from a selected remote
git pull <remote> <branch> # Merge into the current branch the remote branch
<=>
git fetch origin
git merge origin/next
git pull --rebase # pull automatically last modifications on remote (with fetch + merge) & put your validation on head directly
pull all submodules
git submodule foreach git pull
git submodule foreach git pull origin main
git submodule foreach 'git pull origin main || true' # for some submodules without updates"
PUSH
-q, --quiet Suppress all output
-v, --verbose show details
--progress show progress status
git push --all | --branches # push all branches
git push --tags # push all tags
git push -u <upstream> <branch> # Update remote refs along with associated objects
git push -u <upstream> <branch> # set upstream for actual local branch & push it to remote (create one if needed)
git push --tags # push tags also
git push -d <upstream> <branch> # delete remote branch
git push -d <upstream> <tag> # delete remote tag
REMOTE
git remote -v # show upstream
git remote add <name> <url> # add a remote source to repository
git remote add -t <branch> <name> <url> # add a remote source to repository only for the branch <branch>
git remote remove <name> # remove/delete the remote source <name>
git remote rename <name> <new_name> # rename a remote source
git remote set-branches <name> <branch1> <branch2> ... # change list of branches tracked by a remote
git remote set-url [--push] <name> <newurl> [<oldurl>] # manipulate push urls
git remote set-url [--add|--delete] <name> <url> # add or delete url
git remote show # list all upstreams
git remote show <name> # show details for a upstream
REBASE
In the same branch
git co <branch> # put HEAD on branch
git rebase --onto <newcommit> <oldcommit> <HEADcommit> # rebase to <newcommit> with attached HEAD
git push --force-with-lease github HEAD:<branch>
git reset --soft <newcommit> # reset branch to <newcommit>
git co <branch> # put HEAD on branch
After, informs others concerned developers to fetch and reset to the new HEAD
RESET
git reset --merge # resets the index and updates the files in the working tree that are different between <commit> and HEAD
git reset --hard <commit_sha> # reset branch to commit_sha, 'git reflog' is an better way to find commit_sha
git reset --hard HEAD~1
SWITCH
TAG
git tag # List all tags
git show-ref --tags # List all tags with references
git tag -a -m "message" <tag> # Defines an unsigned, annoted tag
git tag -s "tag" -m "message" <tag> # Creates a signed tag with message (define the default key with git config --global user.signingkey before)
git tag -s <tag> -u <keyid> -m <message> <tag> # Creates a signed tag with a specified key user
git tag -d <tag> # Delete existing tags with the given names
git tag -v <tag> # Verify the GPG signature of the given tag names
git show-ref --tags # show sha commits with associated tag
git push --delete origin <tag> # delete tag in origin
# rename tag
git tag -d <old>
git push origin -d <old> | git push origin :old
git tag <new>
git push origin <new> | git push origin --tags
git pull --prune --tags # for coworkers
SUBMODULE
add
git submodule add <url> <name> # Add submodule to actual repository in path <path>
git add .gitmodules <name> # Add new file and path to index
git commit -m "<name>: Add submodule <url> to /<name>" # Commit changes
update
git submodule update --init --recursive <pathspec> # initialize and clone submodules within based on the provided <pathspec>
remove
git rm --cached $pathsubmodule # delete main entry point in git
rm -rf .git/modules/$pathsubmodule # delete submodule from index
rm -rf $pathsubmodule # delete files of submodule
- In file <repo>/.gitmodules, remove section for the corresponding submodule
git add .gitmodules # add modifications in .gitmodules file to index
git commit -m "Remove submodule $pathsubmodule"
git push <upstream> <branch> # git push github main # push branch to origin
clone repo & submodules
git clone --no-remote-submodules <url> <path> # clone repo whithout associated submodules
git clone <url> <path>
git clone --remote-submodules <url> <path> # clone will use the status of the submodule’s remote-tracking branch. After use 'git submodule init' and 'git submodule update'
git clone --recurse-submodules <url> <path> # clone repository and its all submodules recursively
git clone --recurse-submodules[=<pathspec>] <url> <path> # clone repository and its filtered submodules by pathspec
STASH
git stash # Stash the changes in a dirty working directory away
git stash push -m "message" # Stash with a message
git stash list # List all stahes
git stash apply stash@{<index>} # Apply a sepcific stash
git stash pop # Apply the last stash and delete it
git stash drop stash@{<index>} # Drop a specific stash
git stash clear # Delete all stashes
git stash branch <branchname> stash@{<index>} # create a branch from a specific stash
GPG
https://kamarada.github.io/en/2019/07/14/using-git-with-ssh-keys/
GITIGNORE
https://www.atlassian.com/git/tutorials/saving-changes/gitignore
pattern
**/path # match directories anywhere in the repository, relative definition
*.pattern # matches zero or more characters
!pattern # mark to a pattern negates it
/pattern # matches files only in the repository root
path/ # appending a slash indicates the pattern is a directory
debug?.log # a question mark matches exactly one character
debug[0-9].log # Square brackets matches a single character from a specified range like [01] [a-z] [A-Z]
debug[!01].log # an exclamation mark matches any character except one from the specified set
logs/**/debug.log # a double asterisk matches zero or more directories like logs/*day/debug.log
example
*.ba[kt]
*~
!myfile.a # include file in repo
tmp/ # exclude all files in directory tmp
head/**/*.tmp # exclude all files *.tmp in subdirectory of head
TRICKS
install
pipx
sudo pacman -S python-pipx # archlinux, manjaro, ...
sudo apt-get install pipx # ubuntu, debian, ...
pipx install pipenv
pip
sudo pacman -S python-pipx # archlinux, manjaro, ...
sudo apt-get install python3-pip # ubuntu, debian, ...
pip install pipenv
use
mkdir my_project
cd my_project
pipenv --version # show program's version number and exit
pipenv --python <version> # install Python version if its available (use pyenv)
pipenv install requests # required packages
pipenv install numpy matplot ... # install pip packages
pipenv run pip list # List all pip installed packages
pipenv graph # Display currently-installed dependency graph information
pipenv uninstall <package> # remove pip package from virtualenv
pipenv shell # Spawn a shell within the virtualenv
pipenv run python script.py # Spawn a command installed into the virtualenv
pipenv --where # Output project home information.
pipenv --venv # Output virtualenv information.
pipenv --py # Output Python interpreter information
pipenv requirements # Generate a requirements.txt from Pipfile.lock
Pipfile : Liste des dépendances et des packages en développement
Pipfile.lock : Version exacte des dépendances installées (pour la reproductibilité)
pipenv remove # Remove the virtualenv for the current project
cd my_project && rm Pipfile Pipfile.lock # delete files from project directory
pipx install --user --upgrade pipenv # update the packages regularly
eclipse
pipenv install matplot numpy setuptools sympyinstall
sudo pacman -S tk pyenv # archlinux, manjaro, ...
sudo apt-get install pyenv python3-tk # ubuntu, debian, ...
use
pyenv versions # list all installed Python version(s)
pyenv install --list # list all available Python versions
pyenv install <version> # install a specific Python version
pyenv version # Show the current Python version(s) and its origin
pyenv version-file # Detect the file that sets the current pyenv version
pyenv version-name # Show the current Python version
pyenv version-origin # Explain how the current Python version is set
pyenv uninstall <version> # Uninstall Python version
pyenv global # Set or show the global Python version(s)
pyenv local # Set or show the local application-specific Python version(s)
pyenv exec # Run an executable with the selected Python version
pyenv shims # List existing pyenv shims
pyenv whence # List all Python versions that contain the given executable
pyenv which # Display the full path to an executableexport LIBVIRT_DEFAULT_URI=qemu:///system # for virsh autoconnection
pth=/vms/virt
domain=cuckoo-1804
newdomain=cuckoo-1804-clone
pthdisk=$pth/${domain}.qcow2
pthnewdisk=$pth/${domain}-clone.qcow2
pthtmp=/vms/share/${domain}-${date +%s}
lssnapshot=$(virsh snapshot-list $domain --name)
[ -d ${pthtmp} ] || mkdir -p ${pthtmp}
# dump snapshots
for snapshot in ${lssnapshot}; do
virsh snapshot-dumpxml --domain ${domain} ${snapshot} > ${pthtmp}/${domain}_${snapshot}.xml
done
# create a volatily image
sudo qemu-img create -f qcow2 ${pthnewdisk} 100M
# clone domain
virt-clone --original ${domain} --name ${newdomain} --file ${pthnewdisk} --preserve-data
# restore snapshots to empty disk
for snapshot in ${lssnapshot}; do
virsh snapshot-create ${newdomain} --xmlfile ${pthtmp}/${domain}_${snapshot}.xml --atomic
done
# verify snapshots list
echo "- domain snapshots:"
virsh snapshot-list ${newdomain}
# full copy disk / qemu-img convert loses snapshots
sudo cp -a ${pthdisk} ${pthnewdisk}
# verify image snapshots list
echo "- disk snapshots:"
qemu-img snapshot -l ${pthnewdisk}
echo "Launch domain ${newdomain} in virt-manager (restart virt-manager)MASTER
echo -e -n "Give the domain name: " && read domain
echo -e -n "Give the path of pool (/vms/virt) : " && read pth_pool
pth_pool=${pth_pool:-/vms/virt}
echo -e -n "Give the path of disk ($pth_pool/${domain}.qcow2) : " && read pth_disk
pth_disk=${pth_disk:-$pth_pool/${domain}.qcow2}
pth_pool=/vms/virt
domain=cuckoo-1804
pth_disk=$pth_pool/${domain}.qcow2
sdate=$(date +%s)
pth_xml=/vms/share/${domain}-${sdate}
export LIBVIRT_DEFAULT_URI=qemu:///system # for virsh autoconnection
[ -d ${pth_xml} ] || mkdir -p ${pth_xml}
# dumps
echo "> ${domain}"
virsh dumpxml ${domain} > ${pth_xml}/${domain}.xml
for snapshot in $(virsh snapshot-list $domain --name); do
echo " ${snapshot}"
virsh snapshot-dumpxml --domain ${domain} ${snapshot} > ${pth_xml}/${domain}_${snapshot}.xml
done
pth=/tmp/${domain}::${sdate}.tar.gz
cd ${pth_xml}
tar czf ${pth} *
echo -e "\nPlease copy this files to slave:"
echo ${pth}
echo ${pth_disk}
SECOND
echo -e -n "Give the path of snapshots compressed files: " && read pth_tgz
echo -e -n "Give the path of copied disk: " && read pth_disk
echo -e -n "Give the path of pool (/vms/virt) : " && read pth_pool
pth_pool=${pth_pool:-/vms/virt}
export LIBVIRT_DEFAULT_URI=qemu:///system # for virsh autoconnection
domain=${pth_tgz##*/}; domain=${name%::*}
sdate=${pth_tgz##*::}; sdate=${sdate%%.*}
pth_disk=${pth_pool}/${domain}.qcow2
pth_xml=/vms/share/${domain}-${sdate}
[ -d "${pth_xml}" ] || mkdir -p "${pth_xml}"
tar xzf ${pth_tgz} -C "${pth_xml}"
# create a volatily image
sudo qemu-img create -f qcow2 ${pth_disk} 100M
# define domain
virsh define ${pth_xml}/${domain}.xml
virt-clone --original ${domain} --name ${domain} --file ${pth_disk} --preserve-data
# restore snapshots to empty disk
for snapshot in ${lssnapshot}; do
virsh snapshot-create ${domain} --xmlfile ${pth_tmp}/${domain}_${snapshot}.xml --atomic
done
# verify snapshots list
echo "- domain snapshots:"
virsh snapshot-list ${domain}
# full copy disk / qemu-img convert loses snapshots
if ! [ "${pth_disk%%/*}" = /vms/virt ]; then
echo "copy disk from '${pth_disk}' to '/vms/virt/${pth_disk##*/}'"
sudo cp -a ${pth_disk} ${pth_disk}
fi
# verify image snapshots list
echo "- disk snapshots:"
qemu-img snapshot -l ${pth_disk}
echo "Launch domain ${domain} in virt-manager (restart virt-manager)/etc/libvirt/qemu/: path of xml domain files
connect
export LIBVIRT_DEFAULT_URI=qemu:///system # to use sumply virsh <command>
virsh -c qemu:///system # enter in virsh console
virsh -c qemu:///system <command> # execute only a virsh command (needed for dumping to file)
help
help # list all commands with a one line description
help <command> # show complete description & options
domains
monitor
domblkerror # Show errors on block devices
domblkinfo # domain block device size information
domblklist # list all domain blocks
--inactive # get inactive rather than running configuration
--details # additionally display the type and device value
domblkstat # get device block stats for a domain
domcontrol # domain control interface state
domif-getlink # get link state of a virtual interface
domifaddr # Get network interfaces' addresses for a running domain
domiflist # list all domain virtual interfaces
domifstat # get network interface stats for a domain
dominfo # domain information
dommemstat # get memory statistics for a domain
domstate # domain state
domstats # get statistics about one or multiple domains
domtime # domain time
list # list domains
--state-running
--inactive # list only all inactive domains
--state-shutoff
--all # list all domains
--with-snapshot # list domains with existing snapshot
--without-snapshot # list domains without a snapshot
--with-checkpoint # list domains with existing checkpoint
--without-checkpoint # list domains without a checkpoint
others
attach-disk <domain> <source> <target> # attach-disk <domain> <source> <target>
--targetbus <string # target bus of disk device
--driver <string> # driver of disk device
--subdriver <string> # subdriver of disk device
--iothread <string> # IOThread to be used by supported device
--cache <string> # cache mode of disk device
--io <string> # io policy of disk device
--type <string> # target device type
--mode <string> # mode of device reading and writing
--sourcetype <string> # type of source (block|file|network)
--serial <string> # serial of disk device
--wwn <string> # wwn of disk device
--alias <string> # custom alias name of disk device
--rawio # needs rawio capability
--address <string> # address of disk device
--multifunction # use multifunction pci under specified address
--print-xml # print XML document rather than attach the disk
--source-protocol # <string> protocol used by disk device source
--source-host-name # <string> host name for source of disk device
--source-host-transport # <string> host transport for source of disk device
--source-host-socket <string> # host socket for source of disk device
--persistent # make live change persistent
--config # affect next boot
--live # affect running domain
--current # affect current domain
create <file> # create a domain from an XML file
--console # attach to console after creation
--paused # leave the guest paused after creation
--autodestroy # automatically destroy the guest when virsh disconnects
--pass-fds <string> # pass file descriptors N,M,... to the guest
--validate # validate the XML against the schema
--reset-nvram # re-initialize NVRAM from its pristine template
define <file> # define (but don't start) a domain from an XML file
--validate # validate the XML against the schema
detach-disk <domain> <target> # detach disk device (target is the device name in domain)
--persistent # make live change persistent (use to detach when the domain is inactive)
--config # affect next boot
--live # affect running domain
--current # affect current domain
--print-xml # print XML document rather than detach the disk
dumpxml <domain> # Output the domain information as an XML dump to stdout
--inactive # show inactive defined XML
--security-info # include security sensitive information in XML dump
--update-cpu # update guest CPU according to host CPU
--migratable # provide XML suitable for migrations
pool
# list
pool-list # list pools
--inactive # list inactive pools
--all # list inactive & active pools
--autostart # list pools with autostart enabled
--no-autostart # list pools with autostart disabled
--type <string> # only list pool of specified type(s) (if supported)
--details # display extended details for pools
--uuid # list UUID of active pools only
--name # list name of active pools only
# info
pool-info <pool> # storage pool information
# refresh
pool-refresh # refresh a pool
volume
# list
vol-list <pool> # list volumes from a pool
--details # display extended details for volumes
# info
vol-info <vol> <pool> # show storage volume informations
vol-info --pool <pool> <vol>
# clone
vol-clone --pool <pool> <vol> <clonevol> # Clone an existing volume within the parent pool
--prealloc-metadata # preallocate metadata (for qcow2 instead of full allocation)
--reflink # use btrfs COW lightweight copy
# delete
vol-delete --pool <pool> <vol> # delete a vol
--delete-snapshots # delete snapshots associated with volume (must be supported by storage driver)
# upload
vol-upload --pool <pool> <vol> <file> # upload (import) file contents to a volume
# dumpxml
vol-dumpxml --pool <pool> <vol> # output the vol information as an XML dump to stdout
virsh vol-dumpxml <vol> <pool> > <file> # dump into file
# wipeexport LIBVIRT_DEFAULT_URI=qemu:///system
vol-wipe --pool <pool> <vol> # wipe a vol. Ensure data previously on a volume is not accessible to future reads
--algorithm <string> # perform selected wiping algorithm (ex: zero, nnsa, dod, pfitzner7, pfitzner33, random)
# key
vol-key --pool <pool> <vol> # returns the volume key for a given volume name or path
# path
vol-path --pool <pool> <vol> # returns the volume path for a given volume name or key
--pool <string> # pool name or uuid
--offset <number> # volume offset to upload to
--length <number> # amount of data to upload
--sparse # preserve sparseness of volume
backup
# dumpxml
backup-dumpxml <domain> # Dump XML for an ongoing domain block backup job
# backup
backup-begin <domain> # Start a disk backup of a live domain. Use XML to start a full or incremental disk backup of a live domain, optionally creating a checkpoint
--backupxml <string> # domain backup XML
--checkpointxml <string> # domain checkpoint XML
--reuse-external # reuse files provided by caller
snapshot
# list
snapshot-list <domain> # list all snapshots from a domain (domain name, id or uuid)
--tree # list snapshots in a tree
--current # limit list to children of current snapshot
--name # list snapshot names only
--parent # add a column showing parent snapshot
--roots # list only snapshots without parents
--leaves # list only snapshots without children
--no-leaves # list only snapshots that are not leaves (with children)
--metadata # list only snapshots that have metadata that would prevent undefine
--no-metadata # list only snapshots that have no metadata managed by libvirt
--internal # filter by internal snapshots
--external # filter by external snapshots
--from <snapshot> # limit list to children of given snapshot
--descendants --from <snapshot> # list all descendants from one snapshot
--descendants --current
# info
snapshot-info <domain> <snapshot> # show snapshot informations (domain name, id or uuid)
# revert
snapshot-revert <domain> [<snapshot>] # Revert a domain to a snapshot
--snapshotname <snapshot> snapshot name
--current # revert to current snapshot
--running # after reverting, change state to running
--paused # after reverting, change state to paused
--force # try harder on risky reverts
--reset-nvram # re-initialize NVRAM from its pristine template
# dumpxml
snapshot-dumpxml --domain <domain> <snapshot> # dump snapshot definition to stdout
--domain <domain> # domain name, id or uuid
--security-info include security sensitive information in XML dump
virsh snapshot-dumpxml --domain <domain> <snapshot> > <file> # dump into file
tricks
dumpxml all domains
pthxml=/vms/virt/xml-$(date "+%Y%m%d")
# xml
! [ -d ${pthxml} ] && sudo mkdir -p ${pthxml} && sudo chown 1000:1000 ${pthxml}
echo "--> ${pthxml}"
for domain in $(virsh list --all --name); do
echo "> ${domain}"
virsh dumpxml ${domain} > ${pthxml}/${domain}.xml
for snapshot in $(virsh snapshot-list $domain --name); do
echo " ${snapshot}"
virsh snapshot-dumpxml --domain ${domain} ${snapshot} > ${pthxml}/${domain}:${snapshot}.xml
done
done
export all domains & insternal snapshots to appliances
pthpool=/vms/virt
pthapl=${pthpool}/appliances
pthxml=${pthpool}/xml-$(date "+%Y%m%d")
which pigz || { echo "Install pigz"; exit; }
cd ${pthpool} || { echo "Unable to enter in ${pthpool}"; exit; }
for pth in ${pthxml} ${pthxml}; do sudo mkdir -p ${pth} && sudo chown 1000:1000 ${pth}; done
for domain in $(virsh list --all --name); do
echo "> ${domain}"
virsh dumpxml ${domain} > ${pthxml}/${domain}.xml
for snapshot in $(virsh snapshot-list $domain --name); do
echo " ${snapshot}"
virsh snapshot-dumpxml --domain ${domain} ${snapshot} > ${pthxml}/${domain}:${snapshot}.xml
done
file=${pthapl##*/}/${domain}-$(date "+%Y%m%d").tar.gz
echo ">>> ${file}"
tar -cI pigz -f ${file} ${domain}.qcow2 ${pthxml##*/}/${domain}.xml ${pthxml##*/}/${domain}:*.xml
done
sudo chown 1000:1000 -R ${pthapl}
clone domain with internal snapshots
See: virsh - migrate
migrates domain to another host with internal snapshots
See: virsh - clone
Ubuntu
extract deb files
file=mudita24_1.0.3+svn13-7build3_amd64.deb
pth=${file%\.*}
mkdir -p ${pth}/data && ar x --output=${pth} ${file}
tar -xf ${pth}/data.tar.zst -C ${pth}/data
tree ${pth}/data # to view contentsCommands
dconf list /<path>[:]/
dconf read /<path>[:]/<key>
dconf write /<path>[:]/<key> "<value> <value> ..."
dconf dump /<path>[:]/ > <file>
dconf load /<path>[:]/ < <file>
Tricks
profiles
# list
dconf list /org/gnome/terminal/legacy/profiles:/ # list all profiles
dconf list /org/gnome/terminal/legacy/profiles:/:1d5ff56e-96be-4d97-84c1-99a625d4054e/ # list all keys
# keys/values
dconf read /org/gnome/terminal/legacy/profiles:/:1d5ff56e-96be-4d97-84c1-99a625d4054e/background-color # read values for key background-color
# dump profiles
dconf load /org/gnome/terminal/legacy/profiles:/ > <file> # dump gnome-terminal profiles
dconf dump /org/gnome/terminal/legacy/profiles:/nikita/ > <file> # dump gnome-terminal profile for user nikita
# load profiles
dconf load /org/gnome/terminal/legacy/profiles:/ < <file> # load all profiles
dconf load /org/gnome/terminal/legacy/profiles:/<profil>/ < <file> # load a user profile
screensaver
dconf write /org/gnome/desktop/screensaver/lock-delay "uint32 3600" # set delaying screensaver to 3600sInstall
https://virtualenv.pypa.io/en/latest/installation.html
manjaro
sudo pacman -S --needed python python-pipx
pipx install virtualenv
Use
https://virtualenv.pypa.io/en/latest/cli_interface.html#creator
virtualenv <path> # create the virtual environment in <path>
virtualenv --creator <path> # create the virtual environment in <path> with specific creator like : cpython3-mac-brew, cpython3-mac-framework, cpython3-posix, cpython3-win, graalpy-posix, graalpy-win, pypy3-posix, pypy3-win, venv
<path>/bin/activate # activate the virtual environment
deactivate # deactivate the virtual environment
which python3 # to view the referred python pahUsefull
options
-graft-points Allow to use graft points for filenames
-J, -joliet Generate Joliet directory information
-o FILE, -output FILE Set output file name
-quiet Run quietly
-r, -rational-rock Generate rationalized Rock Ridge directory information
-R, -rock Generate Rock Ridge directory information
-root DIR Set root directory for all new files and directories
commands
mkisofs -Jr -o <file> <path> <pat2h> ... # create an iso file from paths
mkisofs -Jr -o <file> -graft-points /<virtualpath1>=/<physicalpath1> /<virtualpath2>=/<physicalpath2> ... # create an iso file from paths with corresponding virtualpath=physicalpath
# create an iso file 'desktop-install.iso' with virtual paths: /bs, /desktop-manjaro and /desktop-ubuntu
mkisofs -Jr -o /vms/iso/desktop-install.iso -graft-points /bs=/home/shared/repo/bs /desktop-manjaro=/home/shared/repo/desktop-manjaro /desktop-ubuntu=/home/shared/repo/desktop-ubuntu /desktop-debian=/home/shared/repo/desktop-debianlock/unlock
faillock
faillock --user nikita # show failed login
faillock --reset --user nikita # reset the number of failed login. Allow to login after pam restrict access for example "too many tries"
passwd
passwd --status # show status of user <user>
passwd -S <user>
passwd --lock <user> # lock user <user>
passwd -l <user>
passwd --unlock <user> # unlock user <user>
passwd -u <user>
usermod
usermod --lock <user> # lock user <user>
usermod -L <user>
usermod --unlock <user> # unlock user <user>
usermod -U <user>TRICKS
create a local git repository and publish it to github
- create the repo on github
- on local repo:
cd <my_local_repo> git init echo "# <my_local_repo>" >> README.md git commit -m "first commit: Initialize repo" git co main git remote add [-t <branch>] -m main [--mirror=(fetch|push)] <name> <URL> # git remote add -m main github git@github.com:aguytech/docker_alpine-alias.git git remote -v git push -u <name> main # for only main git push --all -u <name> main # for all branches # git push -u github main
connection with ssh
- import public key to github
- test
ssh -T -i $private_key_file git@github.com # test ssh connection ssh -T -i $private_key_file -p 443 git@ssh.github.com # test ssh connection over https ssh-add $private_key_file # avoids the repeated entry of secret phrases - set the default key
git config --global user.signingkey $privaye_key_file # for ssh - test with git command
GIT_SSH_COMMAND="ssh -i $privaye_key_file -vvv" git pull
change remote url for remote existing repository
git remote -v # print https://github.com/user/project
git remote set-url origin git@github.com:user/project.git # change the connection url to use ssh
git remote -v # print git@github.com:user/project.git
delete tags
git tag -d [tag];
git push origin :[tag]
git tag -d [tag]
git push origin :refs/tags/[tag]
create orphan repo from another
Create origin to remote server
repo_local="shaarli-snippets"
tmp_branch="dev"
origin="github"
url_origin="git@github.com:aguytech/Shaarli-snippets.git"
upstream="shaarli"
url_upstream="git@github.com:aguytech/Shaarli.git"
upstream_branch="v0.11-snippets" # remote branch to track
mkdir -p "$repo_local"
cd "$repo_local"
git init
# remote
git remote add "$origin" "$url_origin"
git remote add -t "$upstream_branch" "$upstream" "$url_upstream"
git remote -v
git config --get-regexp '^remote'
# upstream
git fetch "$upstream"
git co --orphan="$tmp_branch" "$upstream"/"$upstream_branch"
git st
git ci -m "Initialize branch from $upstream/$upstream_branch $(git log --pretty=format:'%h' -n 1 "$upstream"/"$upstream_branch")"
# origin
git push --set-upstream "$origin" "$tmp_branch"
git co -b master
git push --set-upstream "$origin" master
git br -vv
git br -rlv github/*
# archive
git archive --format tar.gz -9 -o "master.$(date +%s).tar.gz" masterssh-keygen -t ed25519 -C "comment" # generate a keys pair with protocol ed25519 (better than rsa)Dockerfile
...
COPY ./.rc /root/
...
ENV ENV="/root/.rc"
ENTRYPOINT ["/bin/sh"]
...config.json
{
"auths": {},
"credsStore": "desktop",
"currentContext": "default",
"detachKeys": "ctrl-x,x"
}dockerfile
docker build -t <name>:<tag> <path_dockefile> # build from path with Dockerfile an image
image
docker image ls # list all images in repo
docker images
docker images --filter "dangling=true" # list only "not labelled" images
docker images -f "label!=alpine" # list only "not labelled" images
docker images -f "reference=alpine" -f "before=alpine:latest" # list only "not labelled" images
#-f or --filter format is of "key=value"
# dangling (boolean - true or false)
# label (label=<key> or label=<key>=<value>)
# before (<image-name>[:<tag>], <image id> or <image@digest>)
# since (<image-name>[:<tag>], <image id> or <image@digest>)
# reference (pattern of an image reference)
docker image rm <image> .. # delete all docker images in repository
docker rmi $(docker images -f "dangling=true" -q) # delete "dangled" docker images
docker image rmi
docker image rm $(docker images -q) # delete all docker images in repository
docker image prune # delete all unused docker images by containers in repository
docker image tag source_image[:tag] target_image[:new_tag] # Create a tag target_image that refers to source_image
docker tag source_image[:tag] target_image[:new_tag] # Create a tag target_image that refers to source_image
container
docker run -dit -p 8090:80 --name <container> <image> # run detached container with name
docker run --rm <image> # run ephemeral container & associated volumes
docker container attach <container> # Attach local standard input, output, and error streams to a running container
docker attach <container>
docker commit -a <author> -c <Dockerfile> -m <message> <container> [repository[:tag]] # Create a new image from a container's changesGet
- get URL from web page
https://docs.docker.com/desktop/release-notes/
url='https://desktop.docker.com/linux/main/amd64/209931/docker-desktop-x86_64.pkg.tar.zst?utm_source=docker&utm_medium=webreferral&utm_campaign=docs-driven-download-linux-amd64'
path=/home/.tmp/docker-desktop
mkdir -p ${path}
-----
curl ${url} | sudo tar xvf - --zstd -C ${path}
----- or
file=docker-desktop-x86_64.pkg.tar.zst
curl ${url} -O ${file}
tar xvf ${file} -C ${path}
-----
Install
sudo cp -a ${path}/opt/* /opt/
sudo cp -a ${path}/usr/bin/* /usr/bin/
sudo cp -a ${path}/usr/lib/docker /usr/lib/
sudo cp -a ${path}/usr/lib/systemd/user/* /usr/lib/systemd/user/
sudo cp -a ${path}/usr/share/applications/* /usr/share/applications/
Uninstall
paths="opt/docker-desktop
usr/bin/docker-credential-desktop
usr/lib/docker/
usr/lib/systemd/user/docker-desktop.service
usr/share/applications/docker-desktop-uri-handler.desktop
usr/share/applications/docker-desktop.desktop"
for path in ${paths}; do sudo rm -fR ${path}; done/var/lib/docker
docker info | grep 'Storage Driver'
btrfs
btrfs subvolume create docker-zetar
echo "UUID=2732b516-0c65-4b4c-ac56-a9865132649d /home/nikita btrfs defaults,noatime,ssd,space_cache=v2,autodefrag,compress=zstd,subvol=/user-zetar 0 2"
docker
su -
systemctl stop docker.service docker.socket
cp -a /var/lib/docker /var/lib/docker.bk
rm -fR /var/lib/docker/*
mount /var/lib/docker
systemctl daemon-reload
cp -a /var/lib/docker.bk/* /var/lib/docker/
# /etc/docker/daemon.json
path=/etc/docker
file="${path}/daemon.json"
[ -d ${path} ] || mkdir ${path}
[ -f ${file} ] || echo "{
}" > ${file}
if grep -q storage-driver ${file}; then
sed -i '/storage-driver/ s|"storage-driver.*"|"storage-driver": "btrfs"|' ${file}
else
sed -i '/}/i\ "storage-driver": "btrfs"' ${file}
fi
systemctl start docker.service docker.socket
systemctl status docker
docker info | grep 'Storage Driver'
docker info | grep 'Storage Driver' MANJARO
Install
sudo pacman -Syu
sudo pacman -S docker
Service
sudo systemctl start docker.service
sudo systemctl enable docker.service
sudo systemctl status docker
User
sudo usermod -aG docker ${USER}
reboot
--------------- UBUNTU
User
docker pull hello-world
docker run hello-world
Basic commands
docker images # list all images
docker container ls # list all containers
docker stats # CPU, RAM, and network usage of running images
docker network ls # show all available networksstart
log mimikatz.log
lsadump
cd {$path_hive}
log c:\lsadump.log
lsadump::sam /system:SYSTEM /sam:SAM
exit